sequencing-oauth-api-swift 2.5.0

sequencing-oauth-api-swift 2.5.0

许可证 MIT
发布最后发布2017年3月

Alex MoskvinBogdan Laukhin 维护。



  • 作者:
  • Sequencing

此仓库包含 CocoaPods 插件代码,实现 Sequencing.com 的 OAuth2 认证,以便您的 Swift iOS 应用可以安全访问 Sequencing.com 的 API 和应用链。

  • OAuth 流程在此处解释here
  • 使用此 Pod 的示例位于here

内容

  • Cocoa Pod 集成
  • 资源
  • 维护者
  • 贡献

Cocoa Pod 集成

如果您想在新项目或现有项目中安装和使用 OAuth 逻辑,请遵循以下说明。

  • 在 Xcode 中创建新项目

  • 安装 pod

    • 请参阅 CocoaPods 指南
    • 在项目目录中创建 Podfile: $ pod init
    • 不要忘记取消注释行(因为这是一个 Swift pod)use_frameworks!
    • 指定 "sequencing-oauth-api-swift" pod 参数

      pod 'sequencing-oauth-api-swift', '~> 2.5.0'

    • 在项目中安装依赖项: $ pod install

    • 始终打开 Xcode 工作空间而不是项目文件:$ open *.xcworkspace
  • 添加应用程序传输安全性设置

    • 打开项目设置 > 信息选项卡
    • 添加 App Transport Security Settings 行参数(作为字典)
    • 向 App Transport Security Settings 参数添加子行作为 Exception Domains 字典参数
    • 向 Exception Domains 参数添加子行,其字符串值为 sequencing.com
    • 向 App Transport Security Settings 参数添加子行,其布尔值为 Allow Arbitrary Loads
    • Allow Arbitrary Loads 布尔值设置为 YES

    sample files

  • 将框架注册到 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 API 使用相关方法(它将返回更新后的令牌): SQOAuth.sharedInstance().token {(token) in}
  • 注册新账户 / 重置密码方法

    • 只需调用 callRegisterResetAccountFlow 方法 - 它将打开对话框弹出 SQOAuth.sharedInstance().callRegisterResetAccountFlow()

资源

维护者

此仓库由 Sequencing.com 积极维护。[发送邮件至 [email protected] 以获取更多信息或打招呼。](https://sequencing.com/)

贡献力量

我们鼓励大家积极地创建分支。如果您有兴趣更新主分支,请向我们发送拉取请求。如果变更具有积极影响,我们将让它保留。