[GH-ISSUE #87] authorizeWithCallbackURL does nothing with Uber #52

Closed
opened 2026-03-03 16:45:14 +03:00 by kerem · 11 comments
Owner

Originally created by @sephethus on GitHub (Aug 2, 2015).
Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/87

I execute the following but nothing happens:

    //UBER
    let REGISTER_URL = "https://login.uber.com/oauth/authorize"
    let CLIENT_KEY = "********************"
    let SERVER_TOKEN = "*********************"
    let CLIENT_SECRET = "**************************"
    let ACCESS_TOKEN_URL = "https://login.uber.com/oauth/token"
    let REDIRECT_URI = "myappname://callback/url"

    func registerWithUber() {
        let params = [String: String]()
        let url = NSURL(string: REDIRECT_URI)
        let oauthUber = OAuth2Swift(consumerKey: CLIENT_KEY, consumerSecret: CLIENT_SECRET, authorizeUrl: REGISTER_URL, responseType: "code")

        oauthUber.authorizeWithCallbackURL(url!, scope: "profile history", state: "", params: params, success: {
            credentials, parameters, response in
                println("Success")
                println(credentials.oauth_token) },

            failure: { (error: NSError) -> Void in
                println("Fail")
        })

    }

Shouldn't it launch the Safari browser to authenticate with Uber?

Originally created by @sephethus on GitHub (Aug 2, 2015). Original GitHub issue: https://github.com/OAuthSwift/OAuthSwift/issues/87 I execute the following but nothing happens: ``` //UBER let REGISTER_URL = "https://login.uber.com/oauth/authorize" let CLIENT_KEY = "********************" let SERVER_TOKEN = "*********************" let CLIENT_SECRET = "**************************" let ACCESS_TOKEN_URL = "https://login.uber.com/oauth/token" let REDIRECT_URI = "myappname://callback/url" func registerWithUber() { let params = [String: String]() let url = NSURL(string: REDIRECT_URI) let oauthUber = OAuth2Swift(consumerKey: CLIENT_KEY, consumerSecret: CLIENT_SECRET, authorizeUrl: REGISTER_URL, responseType: "code") oauthUber.authorizeWithCallbackURL(url!, scope: "profile history", state: "", params: params, success: { credentials, parameters, response in println("Success") println(credentials.oauth_token) }, failure: { (error: NSError) -> Void in println("Fail") }) } ``` Shouldn't it launch the Safari browser to authenticate with Uber?
kerem closed this issue 2026-03-03 16:45:14 +03:00
Author
Owner

@sephethus commented on GitHub (Aug 2, 2015):

I've also tried reversing parameters with response in the success closure but it doesn't change anything. Nothing happens. Nothing in the debug window.

<!-- gh-comment-id:127052374 --> @sephethus commented on GitHub (Aug 2, 2015): I've also tried reversing parameters with response in the success closure but it doesn't change anything. Nothing happens. Nothing in the debug window.
Author
Owner

@sephethus commented on GitHub (Aug 2, 2015):

Further examination through the OAuthSwift method authorizeWithCallbackURL I found this does not happen here:

        if let queryURL = NSURL(string: urlString) {
            println("This happens")
           self.authorize_url_handler.handle(queryURL)
        }

I tried println(urlString) and it looks fine as a URL. I'm not sure why it's not getting converted to NSURL here. There's no reason why it shouldn't. I even added the following above it with no compile errors:

let q = NSURL(string: urlString)

However if I println(q) it becomes nil for some weird reason.

<!-- gh-comment-id:127062178 --> @sephethus commented on GitHub (Aug 2, 2015): Further examination through the OAuthSwift method authorizeWithCallbackURL I found this does not happen here: ``` if let queryURL = NSURL(string: urlString) { println("This happens") self.authorize_url_handler.handle(queryURL) } ``` I tried println(urlString) and it looks fine as a URL. I'm not sure why it's not getting converted to NSURL here. There's no reason why it shouldn't. I even added the following above it with no compile errors: ``` let q = NSURL(string: urlString) ``` However if I println(q) it becomes nil for some weird reason.
Author
Owner

@phimage commented on GitHub (Aug 2, 2015):

The value of urlstring is?
Maybe encoded, maybe special character hidden

<!-- gh-comment-id:127065786 --> @phimage commented on GitHub (Aug 2, 2015): The value of urlstring is? Maybe encoded, maybe special character hidden
Author
Owner

@sephethus commented on GitHub (Aug 2, 2015):

Ok I found the answer. The problem was that the scope was not being percent escaped. "profile history" had to be changed to "profile%20history". This could be fixed by updating that urlString to be percent escaped.

Now I'm getting an entirely different error from uber's page: Invalid Request Parameters

<!-- gh-comment-id:127065824 --> @sephethus commented on GitHub (Aug 2, 2015): Ok I found the answer. The problem was that the scope was not being percent escaped. "profile history" had to be changed to "profile%20history". This could be fixed by updating that urlString to be percent escaped. Now I'm getting an entirely different error from uber's page: Invalid Request Parameters
Author
Owner

@phimage commented on GitHub (Aug 2, 2015):

So maybe a fix needed to encode scope

<!-- gh-comment-id:127066062 --> @phimage commented on GitHub (Aug 2, 2015): So maybe a fix needed to encode scope
Author
Owner

@sephethus commented on GitHub (Aug 2, 2015):

Yes, this worked here:

        if let q = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) {
            println(q)
            if let queryURL = NSURL(string: q) {
                println("This happens too")
                self.authorize_url_handler.handle(queryURL)
            }
        }

However, I'm sure it could be written better.

I still get invalid request parameters though, so not sure what's up with that. This is the url it's sending to UBER:

https://login.uber.com/oauth/authorize?client_id=myclientiddisplayscorrectlyhere&redirect_uri=UGetMe://oauth&response_type=code&scope=profile%20history
<!-- gh-comment-id:127066265 --> @sephethus commented on GitHub (Aug 2, 2015): Yes, this worked here: ``` if let q = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { println(q) if let queryURL = NSURL(string: q) { println("This happens too") self.authorize_url_handler.handle(queryURL) } } ``` However, I'm sure it could be written better. I still get invalid request parameters though, so not sure what's up with that. This is the url it's sending to UBER: ``` https://login.uber.com/oauth/authorize?client_id=myclientiddisplayscorrectlyhere&redirect_uri=UGetMe://oauth&response_type=code&scope=profile%20history ```
Author
Owner

@damianesteban commented on GitHub (Aug 19, 2015):

I'm having the same issue with the GitHub example...authorizeWithCallbackURL currently does nothing.

<!-- gh-comment-id:132435051 --> @damianesteban commented on GitHub (Aug 19, 2015): I'm having the same issue with the GitHub example...`authorizeWithCallbackURL` currently does nothing.
Author
Owner

@sephethus commented on GitHub (Aug 19, 2015):

See above, you'll have to make sure the url string is percent encoded before being passed to the handle method. This is found in OAuth2Swift.swift, I had to add the above lines. This whole thing is a doozy though, took me a while to get and basically I had to just sit down for an hour or two and figure out how OAuthSwift works step by step, now I'm dealing with Uber's sandbox issues.

<!-- gh-comment-id:132436229 --> @sephethus commented on GitHub (Aug 19, 2015): See above, you'll have to make sure the url string is percent encoded before being passed to the handle method. This is found in OAuth2Swift.swift, I had to add the above lines. This whole thing is a doozy though, took me a while to get and basically I had to just sit down for an hour or two and figure out how OAuthSwift works step by step, now I'm dealing with Uber's sandbox issues.
Author
Owner

@damianesteban commented on GitHub (Aug 19, 2015):

I'm working with the Swift 2 branch actually and I'm presenting the login screen with a SFSafariViewController. I was convinced I was using it incorrectly, but this did the trick. Thank you.

<!-- gh-comment-id:132755897 --> @damianesteban commented on GitHub (Aug 19, 2015): I'm working with the Swift 2 branch actually and I'm presenting the login screen with a `SFSafariViewController`. I was convinced I was using it incorrectly, but this did the trick. Thank you.
Author
Owner

@dongri commented on GitHub (Aug 26, 2015):

Hi @sephethus @phimage @damianesteban

I Resolved Uber OAuth problem

https://github.com/dongri/OAuthSwift/pull/96/files

Thanks!

<!-- gh-comment-id:134894668 --> @dongri commented on GitHub (Aug 26, 2015): Hi @sephethus @phimage @damianesteban I Resolved Uber OAuth problem https://github.com/dongri/OAuthSwift/pull/96/files Thanks!
Author
Owner

@sephethus commented on GitHub (Aug 26, 2015):

@dongri there is still an issue in the authorizeWithCallBackURL. Uber gets an Invalid Request Parameters if the callback url is included in the URL string. I have to comment out that line urlString += "&redirect_uri=\(callbackURL.absoluteString!)" just to fix it. Other than that it looks like the main issues are fixed.

<!-- gh-comment-id:135070911 --> @sephethus commented on GitHub (Aug 26, 2015): @dongri there is still an issue in the authorizeWithCallBackURL. Uber gets an Invalid Request Parameters if the callback url is included in the URL string. I have to comment out that line `urlString += "&redirect_uri=\(callbackURL.absoluteString!)"` just to fix it. Other than that it looks like the main issues are fixed.
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#52
No description provided.