AdyenAuthentication iOS SDK

AdyenAuthentication SDK 为安全性要求高的用例(如银行、发卡和 PSD2 强客户认证)提供可重用且易于使用的双重身份验证。

安装

该 SDK 可通过 CocoaPodsCarthageSwift Package Manager 或手动安装方式获取。

CocoaPods

  1. pod 'AdyenAuthentication' 添加到您的 Podfile 中。
  2. 运行 pod install

Carthage

  1. github "adyen/adyen-authentication-ios" 添加到您的 Cartfile 中。
  2. 运行 carthage update
  3. 按照 Carthage Readme 中的描述,将框架链接到您的目标。

动态 xcFramework

将动态 XCFramework/Dynamic/AdyenAuthentication.xcframework 拖到您通用目标设置中的 Frameworks, Libraries, and Embedded Content 部分。 出现提示时,选择“需要时复制项目”。

静态 xcFramework

  1. 将静态 XCFramework/Static/AdyenAuthentication.xcframework 拖到您通用目标设置中的 Frameworks, Libraries, and Embedded Content 部分。
  2. 确保静态 AdyenAuthentication.xcframework 未被嵌入。

Swift Package Manager

  1. 按照 Apple 的 将 Package 依赖项添加到您的 App 指南,了解如何添加 Swift Package 依赖项。
  2. 使用 https://github.com/Adyen/adyen-authentication-ios 作为仓库 URL。
  3. 指定版本至少为 1.0.0

用法

初始化

有两种配置选项。

  1. 使用设备检查 API
let configuration = AuthenticationService.Configuration(localizedRegistrationReason: // Text explaining to the user why we need their biometrics while registration,
                                                        localizedAuthenticationReason: // Text explaining to the user why we need their biometrics while authentication.
                                                        appleTeamIdentifier: // The Apple registered development team identifier.)
self.authenticationService =  AuthenticationService(configuration: configuration)
  1. 使用 Apple Passkeys
let configuration = AuthenticationService.PassKeyConfiguration(
                    relyingPartyIdentifier: "com.example.com",
                    displayName: "App name",
                    consecutiveApprovalCancellationsLimit: Int?
                )
self.authenticationService = AuthenticationService(configuration: configuration)

检查设备支持

let deviceSupport: String = try authenticationService.checkSupport()

如果当前设备不受支持,此调用将抛出错误;否则,将返回一个不透明的字符串有效负载,需要根据用例将其发送到后端 API。

检查设备是否已注册

authenticationService.isDeviceRegistered(withAuthenticationInput: input /*The opaque string sdk input*/) { [weak self] result in
    switch result {
    case let .success(isRegistered):
        /// output is a Boolean indicating whether the current device is registered,
        /// then you can call `authenticate` function below.
    case let .failure(error):
        /// Error raised,
        /// for example if the device is not protected by either pass code, face Id, or fingerprint, or if device is not registered,
        /// then you can call `register` function below.
    }
}

// OR you can also use the async version of this function:

let isDeviceRegistered = try await authenticationService.isDeviceRegistered(withAuthenticationInput: input /*The opaque string sdk input*/)

首次注册

authenticationService.register(withRegistrationInput: input /*The opaque string sdk input*/) { [weak self] result in
    switch result {
    case let .success(output):
        /// output is an opaque string that should be sent to Adyen backend API (depending on the use case) to be validated for registration to be finalized.
    case let .failure(error):
        /// Failure to register the device, for example if the device is not protected by either pass code, face Id, or fingerprint.
    }
}

// OR you can also use the async version of this function:

let sdkOutput = try await authenticationService.register(withRegistrationInput: input /*The opaque string sdk input*/)

用于身份验证

authenticationService.authenticate(withAuthenticationInput: input /*The opaque string sdk input*/) { result in
    switch result {
    case let .success(output):
        /// output is an opaque string that should be sent to Adyen backend API (depending on the use case) to be validated for authentication to be finalized.
    case let .failure(error):
        /// Failure to authenticate, which usually means that the current account is not registered.
    }
}

// OR you can also use the async version of this function:

let sdkOutput = try await authenticationService.authenticate(withAuthenticationInput: input /*The opaque string sdk input*/)

支持

如果您有功能请求,或发现错误或技术问题,请在此处创建 issue

如有其他问题,请联系我们的支持团队

另请参阅

许可

此 SDK 在 Apache License, Version 2.0 下可用。 有关更多信息,请参见 LICENSE 文件。