6 Star 20 Fork 4

北京九州云腾科技有限公司 / IDP2-OIDC-NativeApp-IOS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

IDP-OIDCNativeApp- iOS - 开发文档

更新时间 2017年1月 文档版本号 1.0.0 IDP-OIDCNativeApp公开使用,用于开发者集成参考。

一、介绍

北京九州云腾科技有限公司的IDP产品的口号是统一身份、安全便捷,而IDP单点登录iOS 能够实现IDP身份管家到第三方开发者应用的身份管理和单点登录。

如果对于IDP不熟悉的话,可以联系我们info@idsmanager.com,或者去我们公司的网站http://www.idsmanager.com 详细了解。IDP产品针对的是企业级用户,单点登录。我们为你提供了一个开源地demo应用IDP-OIDCNativeApp,在 MIT License 下可以随意参照修改。该demo应用使用xcode8.0和Swift 3.0开发,如果您的开发方式不一致,可能会导致未知错误。

集成OIDCNaitveApp之后,通过IDP身份管家实现如下效果(也可以集成我们的SDK将IDP身份管家替换成自己的APP):

1.通过IDP身份管家点击集成的OIDCNativeApp

2.选择您要单点登录的用户(如果只关联一个用户则直接跳转到OIDCNativeApp应用单点登录)

3.打开OIDCNativeApp并且根据你选择的用户实现单点登录

输入图片说明

流程图:

输入图片说明

第1步:登录IDP身份管家,点击需要打开的应用,请求IDP Server去获取Token

第2步:IDP Server返回rpToken和idToken给IDP身份管家(Token是客户端请求登录的凭证)

第3步:IDP身份管家通过URL跳转打开集成了OIDC Native App的APP,Web通过URL传递Token给客户端。

第4步:集成了OIDC Native App的APP通过解析URL获取传过来的rpToken、idToken

第5步:App通过获取到的rpToken、idToken,请求RP Server,进行登录请求

第6步:RP Server接收到请求后,去IDP Server验证rpToken、idToken

第7步:IDP Server 返回验证结果给RP Server

第8步:RP Server 处理IDP Server返回的结果,根据结果返回相对的结果给App

已实现的功能: 用OIDC的token验证方式从IDP身份管家跳转到第三方应用,并且获取到由应用:IDP身份管家 传来的参数信息,以在本地应用中无缝连接单点登录,直接进入登录状态。

系统版本支持: iOS9.0+

如有问题,请联系info@idsmanager.com,或致电 010-58732285。


二、使用IDP-OIDCNativeApp

使用IDPNativeApp一共有三步。

  1. 前往Targets -> Info -> URL Types新创建一个URL Type,这之中唯一必填的内容就是 URL Schemes,该项代表着在app之间跳转的唯一标识,在之后的网页上的步骤中会需要填写。URL Scheme不需要和bundle ID或者应用名称一致。

输入图片说明

  1. 在AppDelegate中添加方法(Demo中提供的是Swift3版本,请自行转换成您开发所使用的对应版本):
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        /********************************  接收处理跳转传过来的参数  ******************************/
   if url.scheme == "iOSOIDCNative" {
            let notice = NSNotification.init(name: NSNotification.Name(rawValue: "LoginNotification"), object: nil)
   NotificationCenter.default.post(notice as Notification)
 UserDefaults.standard.set(self .getIdToken(infoURL: url as NSURL), forKey: "OIDCToken")
 self.perform(#selector(postNotifation),with: nil,afterDelay: 0.1)

   }

        return true
       
}

    

    func postNotifation() {
        let notice = NSNotification.init(name: NSNotification.Name(rawValue: "OIDCAutomaticLogin"), object: nil)
        NotificationCenter.default.post(notice as Notification)

    }

3.如果从SP发起,去IDP授权后登录需要调用,IDPNativeAppSDK.open(),参数scheme是调起应用的URL Scheme,appType调起应用的类型,paramString参数: paramString格式: username=xxx&age=xxx&phonexxxx

IDPNativeAppSDK.open(scheme: "jiuzhou", appType: IDPNativeAppType.IDP_BasicNativeApp, paramString: "username=lisi&xxx=xxx){ (success) in
            print(success)
        }

4.获取单点登录的token,IDPNativeAppSDK.getIdToken(infoURL:"url")

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

      IDPNativeAppSDK.getIdToken(infoURL: url as NSURL)
    }

本方法会出当从IDP身份管家应用中跳转过来时候通过URL解析出需要的rpToken、idToken。

Framework安装方法

  1. 从我们的网站直接下载sdk的framework包,或者从demo应用IDPNativeApp https://git.oschina.net/sz_ids/IDP2-NativeApp-IOS 中直接获取IDPNativeAppSDK.framework。
  2. 将IDPNativeAppSDK.framework拖入到项目中的framework文件夹中。

输入图片说明

  1. 在Targets -> General 中下方有一栏叫做Embedded Binaries,将我们的IDPNativeAppSDK添加进去。
  2. 点击下方的 + 号
  3. 在Frameworks中选取IDPNativeAppSDK
  4. 成功将SDK添加到Embedded Binaries中

输入图片说明

尝试build或运行。如果没有出错误的话,到这里SDK的安装就完成了,下面要介绍在Xcode中如何设置和使用SDK。如果在这一步出现错误的话,请删掉重复上面的步骤。您也可以打开我们的demo应用来看我们的集成结果,互相比较。

5 . 最后,在希望获取到用户的账户信息的地方,调用获得的参数发起接口请求(请参照服务器集成文档),如果需要多次使用用户信息,请自行保存。 到这里,Xcode中的设置和使用也已经全部完成,我们现在需要在IDP页面上为本应用配置信息。


三、IDP单点登录设置

IDP(Identity Provider)产品市场名称为:IDP身份管家,支持iOS和Android,在App Store和应用宝上可以下载到。该产品是IDP产品线的重要组成部分,配合网页端可以做到安全、便捷地统一管理和使用自己的账号身份信息。IDP身份管家对于本地应用的身份管理支持,是移动端实现统一所有网络身份的重要模块。IDP提供的本SDK,目的是为企业开发者提供一个可以接入IDP的方法,能够实现从IDP应用到第三方开发应用的账号管理和单点登录。 想要实现IDP的统一账号管理和单点登录,您所在的公司必须要正在使用IDP产品,并且您必须拥有管理员权限。开发者权限是不能够添加IDP-OIDCNativeApp应用的,请注意

1 . 在管理员的IDP界面中,点击添加应用,搜索OIDCNativeApp,这里看到的使我们提供的统一模板,我们使用这个模板,点击添加应用。(如果没有找到该模板,请与九州云腾联系)

输入图片说明

2 . 继续填写需要添加的应用内容。 所属领域:请根据情况选择最合适的,这里的选项不会影响到应用的实现 iOS/Android Scheme URL iOS 的Scheme Url填写您在第二节第一步在Xcode中创建的URL Scheme 账号关联方式:这里选择您希望通过什么方式从IDP身份管家把用户的身份信息传递给你的应用,我们目前支持账号密码的方式和OIDC的token方式。本文档适用于OIDC的token方式

输入图片说明

  1. 请为应用授权用户,以便能让公司用户开始使用。如果您知道如何授权应用,请自行授权并跳过本节讲解。
  • 如何授权:授权指的是将一个企业添加进来的应用交给用户使用的过程。IDP系统中,应用添加好以后,需要授权给用户组,如果应用实在开启(默认)的状态的话,那么该用户组的人就可以在他们的IDPs侯爷看到新添加进来的应用。
    • 从左侧进入授权菜单
    • 从列表中选择刚创建的应用
    • 添加新授权
    • 在新页面中选择想要授权的用户组,比如测试组,管理组等。
      • 如果未创建用户组,可以自行创建。如果未添加用户,请先添加用户,并将其归入一个用户组内。

输入图片说明

  1. 应用到这步已经添加完成,但是我们还需要为授权的用户组中的用户添加该用户在该应用的账号信息,这样才能一一对应将这些信息在跳转时传入第三方应用。如果您知道如何授权添加应用子账号,请自行授权并跳过本节讲解。
  2. 退出登录,并以刚才授权过的用户组中某个用户的身份重新登录系统。如果您刚才的管理员是授权成员组成员之一,那么您不需要登出,只要在右上方导航条下拉菜单中选择用户界面即可跳转到用户身份。
  3. 进入应用子账号菜单,会看到你的所有被授权的应用所添加的账号信息的列表。点击右上角的添加应用子账号按钮。

输入图片说明

  1. 在添加界面中选择正确的应用,并且填入对应您第三方应用有效身份信息的用户名密码。比如我开发了应用叫做「微信改」,我在这里天蝎的就是我希望IDP身份管家能帮我管理,并实现单点登录的对应「微信改」账号。这个账号应该在您应用自己的系统中注册并可以使用。
- 如果您在尝试使用IDPNativeApp这个Demo应用,请在运行OIDCNativeAp后点击注册按钮,并将注册好的信息填写在本步骤中。
  1. 您可以为同一个应用添加多个需要管理的账号,IDP身份管家会在跳转前询问您需要使用哪一个

输入图片说明

我们从前到后,配置好了URL Scheme,在IDP网页端创建好了应用对应了URL Scheme,在授权给目标群组之后,在用户界面给该用户自己添加了目标应用的账号信息。

到此,您的应用应该能够使用IDP身份管家来管理和登录您的应用了!


如果您有宝贵的意见请随时与我们联系info@idsmanager.com 。我们会在未来为IDP使用者和开发者提供更完备的SDK功能,敬请期待!

北京九州云腾团队 2017年1月

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2016 sz-ids Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

OIDC Native APP IOS 展开 收起
Swift 等 3 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Swift
1
https://gitee.com/bjzyt/IDP2-OIDC-NativeApp-IOS.git
git@gitee.com:bjzyt/IDP2-OIDC-NativeApp-IOS.git
bjzyt
IDP2-OIDC-NativeApp-IOS
IDP2-OIDC-NativeApp-IOS
master

搜索帮助