[GH-ISSUE #421] Authorize handler not called - neither success or failure #269

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

Originally created by @markusstaas on GitHub (Dec 11, 2017).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/421

Description:

Hi there, I am connecting to Strava API and can authorize the app successfully, however, the success or failure handler never gets called.

App Delegate Code:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { if (url.host == "oauth-callback") { OAuthSwift.handle(url: url) } return true }

VC Code below:

` func login(){

// Create OAuth Object
let oauthswift = OAuth2Swift(
    consumerKey:    "21913",
    consumerSecret: "a4bef18ded5104e4c6d00b37dfe40b2512b69730",
    authorizeUrl:   "https://www.strava.com/oauth/authorize",
    accessTokenUrl: "https://www.strava.com/oauth/token",
    responseType:   "code"
)
oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift)

    oauthswift.authorize(
        withCallbackURL: URL(string: "oauth-swift://oauth-callback/strava")!,
        scope: "write", state:"mystate",
        success: { credential, response, parameters in
            print(credential.oauthToken)
            // Do your request
    },
        failure: { error in
            print(error.localizedDescription)
    }
    )

}`

OAuth Provider (Twitter, Github, ..):

Strava

OAuth Version:

  • Version 1
  • [x ] Version 2

OS (Please fill the version) :

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

Installation method:

  • Carthage
  • [x ] CocoaPods
  • Manually

Library version:

  • head
  • [x ] 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

Originally created by @markusstaas on GitHub (Dec 11, 2017). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/421 ### Description: Hi there, I am connecting to Strava API and can authorize the app successfully, however, the success or failure handler never gets called. App Delegate Code: ` func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { if (url.host == "oauth-callback") { OAuthSwift.handle(url: url) } return true }` VC Code below: ` func login(){ // Create OAuth Object let oauthswift = OAuth2Swift( consumerKey: "21913", consumerSecret: "a4bef18ded5104e4c6d00b37dfe40b2512b69730", authorizeUrl: "https://www.strava.com/oauth/authorize", accessTokenUrl: "https://www.strava.com/oauth/token", responseType: "code" ) oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift) oauthswift.authorize( withCallbackURL: URL(string: "oauth-swift://oauth-callback/strava")!, scope: "write", state:"mystate", success: { credential, response, parameters in print(credential.oauthToken) // Do your request }, failure: { error in print(error.localizedDescription) } ) }` ### OAuth Provider (Twitter, Github, ..): Strava ### 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 - [x ] 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 2026-03-03 16:47:15 +03:00
Author
Owner

@markusstaas commented on GitHub (Dec 11, 2017):

If I just launch it in Safari and return the app I get the following error message:

The operation couldn’t be completed. (OAuthSwiftError error -10.)

<!-- gh-comment-id:350625326 --> @markusstaas commented on GitHub (Dec 11, 2017): If I just launch it in Safari and return the app I get the following error message: The operation couldn’t be completed. (OAuthSwiftError error -10.)
Author
Owner

@phimage commented on GitHub (Dec 11, 2017):

you must retain the oauthswiftobject in memory
-10 is retain error

<!-- gh-comment-id:350656782 --> @phimage commented on GitHub (Dec 11, 2017): you must retain the `oauthswift`object in memory -10 is retain error
Author
Owner

@markusstaas commented on GitHub (Dec 11, 2017):

Thanks! I appreciate your response! It works now if I use Safari, however, if I use oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift) it won't call the breakpoints on the handlers. Do you have any advise?

Thanks so much!
Markus

<!-- gh-comment-id:350676095 --> @markusstaas commented on GitHub (Dec 11, 2017): Thanks! I appreciate your response! It works now if I use Safari, however, if I use oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift) it won't call the breakpoints on the handlers. Do you have any advise? Thanks so much! Markus
Author
Owner

@phimage commented on GitHub (Dec 13, 2017):

Any errors?

If not you can put a breakpoint in your func application(_ app: UIApplication, open url: URL, ... to see if OAuthSwift.handle(url: url) called

<!-- gh-comment-id:351343666 --> @phimage commented on GitHub (Dec 13, 2017): Any errors? If not you can put a breakpoint in your `func application(_ app: UIApplication, open url: URL, ...` to see if ` OAuthSwift.handle(url: url)` called
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#269
No description provided.