问题
I am building an ios SDK and implementing the oauth flow.
Basically I need to do the following:
- User clicks on a button.
- Sees a webview popup.
- They sign/sign up in the webview, giving permission to access account.
- The webview redirects them back to a url with a code in the url.
- I need to somehow use that code to make an api call to get their access token.
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.
回答1:
Take a look at this example here. It is configured to use our service (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 here) 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 access_token (or better yet the JWT).
来源:https://stackoverflow.com/questions/19148429/oauth-2-0-webview-ios-sdk