SwiftECP 5.0.0

SwiftECP 5.0.0

测试已测试
Lang语言 SwiftSwift
许可证 NOASSERTION
发布最后发布2019年12月
SPM支持 SPM

Tyler ThompsonTanner Stokes 维护。



 
依赖
AEXML-CU~> 5.0.0
Alamofire~> 4.5
ReactiveSwift~> 6.0
XCGLogger~> 7.0
 

SwiftECP 5.0.0

  • Tyler Thompson 和 Tanner Stokes

SwiftECP

Version License Platform

需要在您的 iOS / MacOS 应用程序上执行 Shibboleth 登录但她不想使用一个 webview? 不想处理 XML 或阅读规范? 使用 SwiftECP 让您的工作变得简单!

SwiftECP 是一个符合规范的 Shibboleth ECP 客户端。只需提供凭据和 Shibboleth 受保护的资源 URL,SwiftECP 就会将 Shibboleth 糖果附加到后续请求或注入到 webview 中。

用法

let username = "YOUR_USERNAME"
let password = "YOUR_PASSWORD"
let protectedURL = URL(
    string: "https://app.university.edu"
)!
let logger = XCGLogger()
logger.setup(level: .debug)

ECPLogin(
    protectedURL: protectedURL,
    username: username,
    password: password,
    logger: logger
).start { event in
    switch event {

    case let .value(body):
        // If the request was successful, the protected resource will
        // be available in 'body'. Make sure to implement a mechanism to
        // detect authorization timeouts.
        print("Response body: \(body)")

        // The Shibboleth auth cookie is now stored in the sharedHTTPCookieStorage.
        // Attach this cookie to subsequent requests to protected resources.
        // You can access the cookie with the following code:
        if let cookies = HTTPCookieStorage.shared.cookies {
            let shibCookie = cookies.filter { (cookie: HTTPCookie) in
                cookie.name.range(of: "shibsession") != nil
            }[0]
            print(shibCookie)
        }

    case let .failed(error):
        // This is an AnyError that wraps the error thrown.
        // This can help diagnose problems with your SP, your IdP, or even this library :)

        switch error.cause {
        case let ecpError as ECPError:
            // Error with ECP
            // User-friendly error message
            print(ecpError.userMessage)

            // Technical/debug error message
            print(ecpError.description)
        case let alamofireRACError as AlamofireRACError:
            // Error with the networking layer
            print(alamofireRACError.description)
        default:
            print("Unknown error!")
            print(error)
        }

    default:
        break
    }
}

需求

  • iOS 9.0+ / MacOS 10.11+
  • Xcode 9.2+
  • Swift 5.0

测试

要运行示例项目,请克隆仓库,然后从 Example 目录首先运行 pod install

您可以通过打开示例项目,将用户名、密码和受保护URL替换为自己的来测试您的SP和IdP的ECP配置。

安装

SwiftECP可以通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中

pod "SwiftECP"

待办事项

  • 单元和集成测试
  • 详细文档
  • 支持频道绑定和持有者密钥
  • 更好的IdP发现

欢迎并鼓励提交拉取请求!

贡献者

许可证

SwiftECP在Apache 2.0许可证下可用。有关更多信息,请参阅LICENSE文件。