[GH-ISSUE #419] Redirects back to app but does not fire off success or failure events #270

Closed
opened 2026-03-03 16:47:15 +03:00 by kerem · 0 comments
Owner

Originally created by @dachan on GitHub (Nov 13, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/419

Description:

The app opens the authorize screen but once I click allow, it directs me back to my app without firing off success or failure events.

Can someone help me understand why not?

import Foundation
import OAuthSwift
import SafariServices

extension ViewController {
    
    func doOAuthFitbit2() {
        let oauthswift = OAuth2Swift(
            consumerKey:    "<<OAuth 2.0 Client ID>>",
            consumerSecret: "<<Client Secret>>",
            authorizeUrl:   "https://www.fitbit.com/oauth2/authorize",
            accessTokenUrl: "https://api.fitbit.com/oauth2/token",
            responseType:   "code"
        )
        
        oauthswift.accessTokenBasicAuthentification = true
        self.oauthswift = oauthswift
        oauthswift.authorizeURLHandler = getURLHandler()
        let state = generateState(withLength: 20)
        let _ = oauthswift.authorize(
            withCallbackURL: URL(string: "smart://")!, scope: "profile weight", state: state,
            success: { credential, response, parameters in
                print("success")
                self.testFitbit2(oauthswift)
        },
            failure: { error in
                print("failure")
                print(error.description)
        }
        )
        print("inside doOAuthFitbit2")
    }
    
    func testFitbit2(_ oauthswift: OAuth2Swift) {
        let _ = oauthswift.client.get(
            "https://api.fitbit.com/1/user/-/profile.json",
            parameters: [:],
            success: { response in
                let jsonDict = try? response.jsonObject()
                print(jsonDict as Any)
        },
            failure: { error in
                print(error.description)
        }
        )
    }
    
    func getURLHandler() -> OAuthSwiftURLHandlerType {
        return OAuthSwiftOpenURLExternally.sharedInstance
    }
}

OAuth Provider (Twitter, Github, ..):

Fitbit

OAuth Version:

  • Version 1
  • [x ] Version 2

OS (Please fill the version) :

  • iOS :
  • OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • CocoaPods
  • Manually

Library version:

  • head
  • v1.2 (Swift 4.0)
  • v1.0.0
  • v0.6
  • other: (Please fill in the version you are using.)

Xcode version:

  • 9.0 (Swift 4.0)

  • 9.0 (Swift 3.2)

  • 8.x (Swift 3.x)

  • 8.0 (Swift 2.3)

  • 7.3.1

  • other: (Please fill in the version you are using.)

  • objective c

Originally created by @dachan on GitHub (Nov 13, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/419 ### Description: The app opens the authorize screen but once I click allow, it directs me back to my app without firing off success or failure events. Can someone help me understand why not? ``` import Foundation import OAuthSwift import SafariServices extension ViewController { func doOAuthFitbit2() { let oauthswift = OAuth2Swift( consumerKey: "<<OAuth 2.0 Client ID>>", consumerSecret: "<<Client Secret>>", authorizeUrl: "https://www.fitbit.com/oauth2/authorize", accessTokenUrl: "https://api.fitbit.com/oauth2/token", responseType: "code" ) oauthswift.accessTokenBasicAuthentification = true self.oauthswift = oauthswift oauthswift.authorizeURLHandler = getURLHandler() let state = generateState(withLength: 20) let _ = oauthswift.authorize( withCallbackURL: URL(string: "smart://")!, scope: "profile weight", state: state, success: { credential, response, parameters in print("success") self.testFitbit2(oauthswift) }, failure: { error in print("failure") print(error.description) } ) print("inside doOAuthFitbit2") } func testFitbit2(_ oauthswift: OAuth2Swift) { let _ = oauthswift.client.get( "https://api.fitbit.com/1/user/-/profile.json", parameters: [:], success: { response in let jsonDict = try? response.jsonObject() print(jsonDict as Any) }, failure: { error in print(error.description) } ) } func getURLHandler() -> OAuthSwiftURLHandlerType { return OAuthSwiftOpenURLExternally.sharedInstance } } ``` ### OAuth Provider (Twitter, Github, ..): Fitbit ### OAuth Version: - [ ] Version 1 - [x ] Version 2 ### OS (Please fill the version) : - [x] iOS : - [ ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x] CocoaPods - [ ] Manually ### Library version: - [ ] head - [ ] v1.2 (Swift 4.0) - [ ] v1.0.0 - [ ] v0.6 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [x] 9.0 (Swift 4.0) - [ ] 9.0 (Swift 3.2) - [ ] 8.x (Swift 3.x) - [ ] 8.0 (Swift 2.3) - [ ] 7.3.1 - [ ] other: (Please fill in the version you are using.) - [ ] objective c
kerem closed this issue 2026-03-03 16:47:15 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/OAuthSwift#270
No description provided.