raulriera / AuthenticationViewController

A simple to use, standard interface for authenticating to oauth 2.0 protected endpoints via SFSafariViewController.
MIT License
257 stars 14 forks source link

Can't receive access_token #6

Open AndreyMomot opened 6 years ago

AndreyMomot commented 6 years ago

Does it work correctly fro Twitter/Facebook or Google+ ? Can't manage any of them. Can anyone provide an example with those networks? e.g. I have following url for twitter: "https://api.twitter.com/oauth/authorize/?client_id=\(clientId)&scope=\(scopes.joined(separator: "+"))&redirect_uri=(redirectURI)&response_type=code" accessTokenURL = https://api.twitter.com/oauth/access_token"

redirectURI = "https://www.google.com"

Then, I put my ClientID and Secret, but nothing works. I can login and do not receive my token after switching to redirectURL.

raulriera commented 6 years ago

Hi,

The redirect URL needs to be a callback to your app scheme, check the README instructions on how to setup your project https://github.com/raulriera/AuthenticationViewController/blob/master/README.md

AndreyMomot commented 6 years ago

Still do not have an answer. Could anyone provide a workable example for Twitter, for example? Which url should I use for redirectURI and for requestToken there?

raulriera commented 6 years ago

I'm the creator of this library, I just said in the previous message what redirectURI to use. 🤔

AndreyMomot commented 6 years ago

Yep, thank you. Now I can authenticate, but after that it opens redirect_uri and code from AppDelegate: (authenticationViewController.authenticateWithCode(code)) doesn't retrieve. What am I doing wrong? Doesn't work even with Instagram...

raulriera commented 6 years ago

Can you provide some code example?

AndreyMomot commented 6 years ago

Here you can find it: https://github.com/AndreyMomot/AuthenticationViewController

I just can't get what to use for URL Scheme in my case.

raulriera commented 6 years ago
// Before doing this, you should check the url is your redirect-uri before doing anything. Be safe :)
if let components = URLComponents(url: url, resolvingAgainstBaseURL: false), let queryItems = components.queryItems, let code = queryItems.first?.value {

Have you checked that the URL you are getting here is the scheme you specified? Does it match the one you used in Instagram?

raulriera commented 6 years ago

Make you used OAuthExample://oauth-callback in your Instagram app and also that you are getting the same one in the AppDelegate (previous code snippet)