测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | MIT |
发布最新发布 | 2017年4月 |
由 Arthur Ariel Sabintsev 和 ID>me 维护。
ID.me WebVerify SDK for iOS 是一个库,允许您使用 ID.me 平台验证用户的群组归属状态。为了说明集成过程,已提供了一个示例项目。
欲了解更多信息,请发送电子邮件至 [email protected] 或访问我们的网站。
变更日志可在 CHANGELOG.md 中找到
IDmeWebVerify.h
。在使用 SDK 之前,您必须调用 IDmeWebVerify.initialize(withClientID: String, clientSecret: String, redirectURI: String)
。例如,您可以在 application(didFinishLaunchingWithOptions:)
中这样做。
import IDmeWebVerify
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
IDmeWebVerify.initialize(withClientID: "<client_id>", clientSecret: "<client_secret>", redirectURI: "<custom_scheme://callback>")
}
}
您应该在 http://developer.id.me 获取参数 <client_id>
、<client_secret>
、<custom_scheme://callback>
。
您必须处理 SDK 的重定向调用。为了这样做,您必须在您的应用程序中注册 redirectURI's
的 URL 方案。转到 项目导航器 -> 选择您的目标 -> 信息 -> URL 类型 -> 新建 并将您的 redirectURI 的方案添加到 URL 方案 中。例如:如果您的 redirectURI 是 my_custom_scheme://callback
,则在 URL 方案 中输入 my_custom_scheme
。
在你的 AppDelegate
中,你必须处理当它被调用时的 redirectURL。你可以通过定义相应的代理函数,然后调用 IDmeWebVerifySDK
来处理 URL 来这样做。
如果你的应用支持 iOS 9 及以上版本,请添加以下内容:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let handled = IDmeWebVerify.sharedInstance().application(app, open: url, options: options)
if !handled {
// do something else
}
return handled
}
如果你的应用支持低于 9.0 的 iOS 版本,那么也必须添加这些方法
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let handled = IDmeWebVerify.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
if !handled {
// do something else
}
return handled
}
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
let handled = IDmeWebVerify.sharedInstance().application(app, open: url, options: [:])
if !handled {
// do something else
}
return handled
}
4.0 版本引入了一些变化。在迁移时需要考虑以下一些主要变更:
IDmeWebVerify.initialize
。verifyUserInViewController:withClientID:redirectURI:scope:withResults
已被移除。你现在应该调用 verifyUser(in: UIViewController, scope: String, withTokenResult: IDmeVerifyWebVerifyTokenResults)
,然后在结果回调中调用 getUserProfile(withScope: String?, result: IDmeVerifyWebVerifyProfileResults)
。IDmeWebVerify.sharedInstance().getAccessToken(withScope: String, forceRefreshing: Bool, results: IDmeVerifyWebVerifyTokenResults)
,该调用包含一个带令牌的回调(如果它已过期则刷新)或错误。你应该在向 ID.me 后端发出每一项请求之前调用此方法。最常见的错误是无法刷新令牌以及没有为指定的 scope
存储访问令牌(在登录之前发生)。IDmeWebVerify.h
中看到一些新函数。为了查看工作示例,你可以
WebVerifySample.xcodeproj
ViewController.m
中设置你的 clientID
、clientSecret
、redirectURI
和 scope
your_custom_scheme
替换为你的 redirectURI
在 WebVerifySample-Info.plist
-> URL Types
(或通过 Project Navigator)中验证通过一个 SFSafariViewController 进行,以符合 iOS 中 OAuth 的最佳实践 。这意味着 SDK 将打开 Safari 以用戶登录。你必须调用 verifyUser(in: UIViewController, scope: String, withTokenResult: IDmeVerifyWebVerifyTokenResults)
来启动 SFSafariViewController 以用户进行身份验证。注意不要在另一个验证过程实例仍在进行时调用此方法,因为它会抛出异常。
需要互联网连接,因为验证是通过 webView 进行的。