New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authentication with Google: not matching redirect URL #10
Comments
They look like matching to me. What's the issue?
Removing what? |
The |
We need the This is how OAuth works. Also, the two URL are matching. We don't compare the query string. |
We need the code param in order to exchange it for a token. This is how OAuth works. |
Sorry I'm not being clear enough. I do not want to remove that part from the URL for the OAuth authorisation flow but only for checking if it matches the redirect URL used to initialize the provider. More in detail this code fails: func matchingURLs(a: NSURL, _ b: NSURL) -> Bool {
return (a.scheme, a.host, a.path) == (b.scheme, b.host, b.path)
} That's because print(a.host) returns
while b.host returns
My idea is to improve to implement an improved getter to retrieve the proper host from the URL. |
I don't get the same result. let url = NSURL(string: "foo://urn:ietf:wg:oauth:2.0:oob")!
print(url.host) // "urn"
let redirect = NSURL(string: "foo://urn:ietf:wg:oauth:2.0:oob?code=abc123")!
print(redirect.host) // "urn" |
Maybe you could change the redirect URL to something else ? |
If I try to use I tried a lot of combinations but only that one is working for me :( |
I got |
Thank you for your feedback. I'll try again by using the Provider to find out what is causing this behaviour about different host output. I'll publish the results later in case someone else will have the same issue. |
Yes, let me know please :) |
Hey @fabiomassimo , You might want look at the let google: Provider = {
let provider: Provider = .Google(clientID: "***", clientSecret: "***", redirectURL: "http://anything.com/callback")
provider.useWebView = true
return provider
}() Note that you can set the I tried it with Instagram, Dribbble, Github etc. Let me know if it works with Google and I'll be happy to merge it in Thanks! |
Unfortunately with any callback URL I get back following error:
The only combination the works for me is with following format:
Should we mention this in the README? Last but not least the URL matching algorithm works great now. I got my token back. |
And this is mandatory too:
|
I meant set the callback to When using webviews, we only listen for the What are the mandatory scopes please? |
A lot: https://developers.google.com/identity/protocols/googlescopes |
You have to specify at least one |
I'll leave the scopes part to the user. But if it works, I'll specify |
That's a good idea. Maybe a link in the README or commented in the code to the list of available scopes? |
I'll add a page to the wiki if |
It works great but only with callback format specified before. Is it what you meant? |
I tested with the redirectURL "http://www.hello.com/callback" and it works let google: Provider = {
let provider: Provider = .Google(
clientID: "***",
clientSecret: "***",
redirectURL: "http://www.hello.com/callback"
)
provider.scopes = ["https://www.googleapis.com/auth/adexchange.buyer"]
provider.useWebView = true
return provider
}() |
I get back from Google in the browser:
Same init as yours but with different scope. |
You have to update the redirect on url google... |
Where should I update it? I receive the error with following let google: Provider = {
let provider: Provider = .Google(clientID: "***", clientSecret: "***", redirectURL: "http://www.hello.com/callback")
provider.useWebView = true
provider.scopes = ["https://www.googleapis.com/auth/analytics.readonly"]
return provider
}() |
I did another try with |
Weird but anyway it is not blocking because the I think it is ok to merge |
It's because you didn't update the redirect URL on https://console.developers.google.com |
Yep looking into that right now ;) |
It seems that because it is an iOS app I can only enter my bundle identifier and Google uses that to create a proper redirect URL. I can not see where I can set the redirect URL. Anyway, I'll look into this better in the docs. Thank you. UPDATE: Indeed, I can set a custom redirect URL if I create a OAuth credential for a web client. |
Again, it works with
Did you register on https://console.developers.google.com ? |
I just pushed Use it with Google (and web server) like so: let google: Provider = {
let provider: Provider = .Google(clientID: "***", clientSecret: "***", redirectURL: "http://www.hello.com/callback")
provider.useWebView = true
provider.scopes = ["https://www.googleapis.com/auth/analytics.readonly"]
return provider
}() |
I was trying to perform a login with Google Service.
Hereby the executed code
When the authorisation is granted in the Safari View Controller the redirect URL gets triggered with following format:
This cause an issue for when the library checks if the redirect URL use during the initialisation of the Provider matches the received redirect URL from the
AppDelegate
.I've tried other combination of redirect URL but that's the redirect URL format that the Google guide advocates.
Did anyone experienced this when trying the built in Google Provider?
I think an easy fix would be to match the retrieved URL by removing the GET parameter from the URL but before open a new PR I'd like to receive some feedback about this.
The text was updated successfully, but these errors were encountered: