[GH-ISSUE #609] authorize not returning succes nor failure #399

Closed
opened 2026-03-03 16:48:21 +03:00 by kerem · 7 comments
Owner

Originally created by @Zandew on GitHub (Jul 10, 2020).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/609

Description:

In the completion handler, neither .success nor .failure is being run. The app redirects correctly to the callback URL with all the tokens in the url.

let oauthswift = OAuth2Swift(
    consumerKey:    "4556fff9f1404f0a8aeb3b0944a0f512",
    consumerSecret: "125742a471294976bd01d794031b1a6b",
    authorizeUrl:   "https://accounts.spotify.com/en/authorize",
    responseType:   "token"
)
self.oauthswift = oauthswift

var loginView = (NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "SpotifyLoginVC") as? NSViewController)!
ShowPopover.showPopover(popView: loginView, mainView: statusBarItem.button!, behaviour: .transient, side: .maxY)
oauthswift.authorizeURLHandler = loginView as! OAuthSwiftURLHandlerType

let handle = oauthswift.authorize(
    withCallbackURL: URL(string: "https://zandew.github.io/")!,
    scope: "user-library-modify",
    state:"test12345") { result in
        switch result {
        case .success(let (credential, response, parameters)):
            print("SUCCESS")
        case .failure(let error):
            print("FAIL")
    }
}

Also, is there a better way then instantiate the loginView? If I do oauthswift.authorizeURLHandler = loginView(), the webView becomes nil.
This is the view controller with the webkit

class SpotifyLoginVC: NSViewController, OAuthSwiftURLHandlerType {

    @IBOutlet weak var webView: WKWebView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do view setup here.
    }
    
    func handle(_ myURL: URL) {
        let req: URLRequest = URLRequest(url: myURL)
        self.webView.load(req)
    }
    
}

OAuth Provider? (Twitter, Github, ..):

OAuth Version:

  • Version 1
  • [x ] Version 2

OS (Please fill the version) :

  • [] iOS :
  • [x ] OSX :
  • TVOS :
  • WatchOS :

Installation method:

  • Carthage
  • [x ] CocoaPods
  • Swift Package Manager
  • Manually

Library version:

  • [ x] head
  • v2.1.0
  • v2.0.0
  • v1.4.1
  • other: (Please fill in the version you are using.)

Xcode version:

  • [] 11.4 (Swift 5.2)

  • 11.x (Swift 5.1)

  • 10.x (Swift 5.0)

  • [ x] other: (Please fill in the version you are using.)
    Xcode 11.5

  • [ x] objective c

Originally created by @Zandew on GitHub (Jul 10, 2020). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/609 ### Description: In the completion handler, neither `.success` nor `.failure` is being run. The app redirects correctly to the callback URL with all the tokens in the url. ``` let oauthswift = OAuth2Swift( consumerKey: "4556fff9f1404f0a8aeb3b0944a0f512", consumerSecret: "125742a471294976bd01d794031b1a6b", authorizeUrl: "https://accounts.spotify.com/en/authorize", responseType: "token" ) self.oauthswift = oauthswift var loginView = (NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "SpotifyLoginVC") as? NSViewController)! ShowPopover.showPopover(popView: loginView, mainView: statusBarItem.button!, behaviour: .transient, side: .maxY) oauthswift.authorizeURLHandler = loginView as! OAuthSwiftURLHandlerType let handle = oauthswift.authorize( withCallbackURL: URL(string: "https://zandew.github.io/")!, scope: "user-library-modify", state:"test12345") { result in switch result { case .success(let (credential, response, parameters)): print("SUCCESS") case .failure(let error): print("FAIL") } } ``` Also, is there a better way then instantiate the `loginView`? If I do `oauthswift.authorizeURLHandler = loginView()`, the `webView` becomes `nil`. This is the view controller with the webkit ``` class SpotifyLoginVC: NSViewController, OAuthSwiftURLHandlerType { @IBOutlet weak var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() // Do view setup here. } func handle(_ myURL: URL) { let req: URLRequest = URLRequest(url: myURL) self.webView.load(req) } } ``` ### OAuth Provider? (Twitter, Github, ..): ### OAuth Version: - [ ] Version 1 - [x ] Version 2 ### OS (Please fill the version) : - [] iOS : - [x ] OSX : - [ ] TVOS : - [ ] WatchOS : ### Installation method: - [ ] Carthage - [x ] CocoaPods - [ ] Swift Package Manager - [ ] Manually ### Library version: - [ x] head - [ ] v2.1.0 - [ ] v2.0.0 - [ ] v1.4.1 - [ ] other: (Please fill in the version you are using.) ### Xcode version: - [] 11.4 (Swift 5.2) - [ ] 11.x (Swift 5.1) - [ ] 10.x (Swift 5.0) - [ x] other: (Please fill in the version you are using.) Xcode 11.5 - [ x] objective c
kerem closed this issue 2026-03-03 16:48:22 +03:00
Author
Owner

@phimage commented on GitHub (Jul 11, 2020):

its nil because this not yet loaded. It must be presented OR you have create the link with the outlet in storyboard

Then where are your code to manage "https://zandew.github.io/".? did you can .handle(url when the web view delegate open it?

<!-- gh-comment-id:657016258 --> @phimage commented on GitHub (Jul 11, 2020): its nil because this not yet loaded. It must be presented OR you have create the link with the outlet in storyboard Then where are your code to manage "https://zandew.github.io/".? did you can .handle(url when the web view delegate open it?
Author
Owner

@Zandew commented on GitHub (Jul 11, 2020):

What do you mean by the code I used to manage my personal website? In this project, I don't reference it anywhere else.

<!-- gh-comment-id:657052582 --> @Zandew commented on GitHub (Jul 11, 2020): What do you mean by the code I used to manage my personal website? In this project, I don't reference it anywhere else.
Author
Owner

@phimage commented on GitHub (Jul 11, 2020):

So why did you put this website as callback url?

The callback url is used to return you the oquth token; so the provider will call this url and you must call handle function with it

You can use url scheme as explained in readme or wiki OR you have a web view and a delegate to monitor all url browsed in webview
See demo app

<!-- gh-comment-id:657071873 --> @phimage commented on GitHub (Jul 11, 2020): So why did you put this website as callback url? The callback url is used to return you the oquth token; so the provider will call this url and you must call handle function with it You can use url scheme as explained in readme or wiki OR you have a web view and a delegate to monitor all url browsed in webview See demo app
Author
Owner

@Zandew commented on GitHub (Jul 11, 2020):

I am trying to implement the webview method, is the handle function you are talking about the one I created in SpotifyLoginVC?

<!-- gh-comment-id:657080874 --> @Zandew commented on GitHub (Jul 11, 2020): I am trying to implement the webview method, is the handle function you are talking about the one I created in `SpotifyLoginVC`?
Author
Owner

@Zandew commented on GitHub (Jul 11, 2020):

I got what I wanted using this tutorial http://fusionblender.net/build-macos-app-spotify-connectivity-swift/, but neither of the cases are still being run.

<!-- gh-comment-id:657098433 --> @Zandew commented on GitHub (Jul 11, 2020): I got what I wanted using this tutorial http://fusionblender.net/build-macos-app-spotify-connectivity-swift/, but neither of the cases are still being run.
Author
Owner

@phimage commented on GitHub (Jul 12, 2020):

A lot of code for nothing in this tutorial... but if it could help

All for macOS is in demo app; with the webview delegate

<!-- gh-comment-id:657191526 --> @phimage commented on GitHub (Jul 12, 2020): A lot of code for nothing in this tutorial... but if it could help All for macOS is in demo app; with the webview delegate
Author
Owner

@Zandew commented on GitHub (Jul 14, 2020):

thanks for the heads up, i'm currently slowly but surely removing all the unnecessary bits

<!-- gh-comment-id:658309835 --> @Zandew commented on GitHub (Jul 14, 2020): thanks for the heads up, i'm currently slowly but surely removing all the unnecessary bits
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#399
No description provided.