I am building an ios SDK and implementing the oauth flow.
Basically I need to do the following:<ul><li>User clicks on a button.</li> <li>Sees a webview popup.</li> <li>They sign/sign up in the webview, giving permission to access account.</li> <li>The webview redirects them back to a url with a code in the url.</li> <li>I need to somehow use that code to make an api call to get their access token.</li> </ul>
How can I do the above in objective-c? Meaning how can I show them a webview with my site signup/sign flow, and get access to the access token using the code in the redirected url?
I know how to do the webview, but I am not sure how to get the code to use to make an api call.Answer1:
Take a look at <a href="https://github.com/auth0/Auth0.iOS" rel="nofollow">this example here</a>. It is configured to use <a href="http://developers.auth0.com" rel="nofollow">our service</a> (which implements OAuth 2), but it is open source, so you can modify it to point to whatever OAuth server you are planning to connect to.
The key is the method
shouldStartLoadWithRequest (see <a href="https://github.com/auth0/Auth0.iOS/blob/master/Auth0Client/Auth0WebViewController.m#L99" rel="nofollow">here</a>) that will notify you every time a URL is going to be loaded. If the URL is the final redirect to the callback address (with the token in it ), then you parse it from the request and extract the <strong>access_token</strong> (or better yet the <strong>JWT</strong>).