oauth 2.0 webview ios sdk [英] oauth 2.0 webview ios sdk

查看:63
本文介绍了oauth 2.0 webview ios sdk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 ios SDK 并实现 oauth 流程.

I am building an ios SDK and implementing the oauth flow.

基本上我需要执行以下操作:

Basically I need to do the following:

  • 用户点击按钮.
  • 看到一个 webview 弹出窗口.
  • 他们在网络视图中注册/注册,授予访问帐户的权限.
  • webview 将它们重定向回 URL 中带有代码的 URL.
  • 我需要以某种方式使用该代码进行 api 调用以获取他们的访问令牌.

我怎样才能在objective-c中做到以上几点?这意味着我如何向他们展示我的网站注册/签名流程的 web 视图,并使用重定向 URL 中的代码访问访问令牌?

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?

我知道如何进行 webview,但我不确定如何获取用于进行 api 调用的代码.

I know how to do the webview, but I am not sure how to get the code to use to make an api call.

推荐答案

看看这里的例子.它被配置为使用我们的服务(实现 OAuth 2),但它是开源的,因此您可以对其进行修改指向您计划连接的任何 OAuth 服务器.

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.

关键是方法shouldStartLoadWithRequest(见here) 会在每次加载 URL 时通知您.如果 URL 是最终重定向到回调地址(其中包含令牌),那么您从请求中解析它并提取 access_token(或者更好的是 JWT).

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).

这篇关于oauth 2.0 webview ios sdk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆