此仓库包含 CocoaPods 插件代码,实现 Sequencing.com 的 OAuth2 认证,以便您的 Swift iOS 应用可以安全访问 Sequencing.com 的 API 和应用链。
如果您想在新项目或现有项目中安装和使用 OAuth 逻辑,请遵循以下说明。
在 Xcode 中创建新项目
安装 pod
$ pod init
use_frameworks!
指定 "sequencing-oauth-api-swift" pod 参数
pod 'sequencing-oauth-api-swift', '~> 2.5.0'
在项目中安装依赖项: $ pod install
$ open *.xcworkspace
添加应用程序传输安全性设置
App Transport Security Settings
行参数(作为字典)Exception Domains
字典参数sequencing.com
Allow Arbitrary Loads
Allow Arbitrary Loads
布尔值设置为 YES
将框架注册到 Swift 代码中使用
首先您需要创建一个桥接头文件。选择文件 > 新建 > 文件 > 头文件 > 命名为
project-name-Bridging-Header.h
在桥接头文件中添加 SQOAuthFramework 类导入
#import <OAuth/SQOAuthFramework.h>
在项目设置中注册您的桥接头文件。选择您的项目 > 项目目标 > 构建设置 > Objective-C 桥接头指定路径
$(PROJECT_DIR)/project-name-Bridging-Header.h
注册应用程序参数和代理
订阅您的类以处理授权协议
SQAuthorizationProtocol
通过 shared instance
方法访问 SQOAuth
SQOAuth.sharedInstance()
注册您的应用程序参数和代理
SQOAuth.sharedInstance().registerApplicationParametersCliendID(client_id,
clientSecret: client_secret,
redirectUri: redirect_uri,
scope: scope,
delegate: self)
其中
client_id - your app CLIENT_ID
client_secret - your app CLIENT_SECRET
redirect_uri - your app REDIRECT_URI
scope - your app SCOPE
delegate - UIViewController instance that conform to "SQAuthorizationProtocol" protocol
使用授权方法
实现 SQAuthorizationProtocol 中的方法
func userIsSuccessfullyAuthorized(_ token: SQToken) -> Void { }
func userIsNotAuthorized() -> Void { }
func userDidCancelAuthorization() -> Void { }
您可以通过 authorizeUser
方法授权用户
SQOAuth.sharedInstance().authorizeUser()
在 userIsSuccessfullyAuthorized
方法中,您将接收到 SQToken 对象
accessToken: String
expirationDate: NSDate
tokenType: String
scope: String
refreshToken: String
访问最新的令牌
SQOAuth.sharedInstance().token {(token) in}
注册新账户 / 重置密码方法
callRegisterResetAccountFlow
方法 - 它将打开对话框弹出 SQOAuth.sharedInstance().callRegisterResetAccountFlow()
此仓库由 Sequencing.com 积极维护。[发送邮件至 [email protected] 以获取更多信息或打招呼。](https://sequencing.com/)
我们鼓励大家积极地创建分支。如果您有兴趣更新主分支,请向我们发送拉取请求。如果变更具有积极影响,我们将让它保留。