oauth 2.0 webview ios sdk

淺唱寂寞╮ 提交于 2019-12-24 13:16:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!