Bring the power of CLEAR to your iOS application! The SDK handles both UI and underlying service calls to securely verify a user's identity.
To set up a partnership, reach out to developersupport@clearme.com. The following credentials must be provided to you by CLEAR during onboarding to use the SDK:
File
->Add Packages
Up to Next Major Version
is recommendedAdd Package
ClearMeSDK
is selected and added to the correct targetAdd Package
againClearMeSDK.xcframework
, ClearFaceCapture.xcframework
, ClearUI.xcframework
, Lottie.xcframework
, and TrustKit.xcframework
Copy items if needed
Build Phases
->Link Binary With Libraries
Build Phases
->Embed Frameworks
The SDK exposes the following public classes. Details of each are described in the Usage
section below.
ClearSDK
ClearEnvironment
ClearVerificationSessionDelegate
ClearVerificationUseCase
ClearVerificationIdentifierInput
ClearVerificationEmailInput
ClearVerificationSuccess
ClearVerificationError
ClearVerificationView
ClearSDK
is the root class of the SDK. An application must initialize this class using the Client ID
and API Key
provided by CLEAR during onboarding.
ClearSDK.initialize(clientId: CLIENT_ID, apiKey: API_KEY, environment: .integration)
The SDK uses two environments for different purposes.
integration
: Used during development, debugging and integration testing.production
Used for active application releases. Change initialization to use this environment after proper usage is verified.ClearVerificationView
is a public UI component that automatically trigger the verification flow when tapped.
let clearView = ClearVerificationView(delegate: self)
The ClearVerificationSessionDelegate
protocol provides configuration details to ClearVerificationView
, and handles the results of a verification sessions.
/// A set of methods which provides data required to set-up a verification flow and returns the results of a completed session.
public protocol ClearVerificationSessionDelegate: AnyObject {
/// Provides a view controller to host the CLEAR verification UI flow
var hostViewController: UIViewController { get }
/// Provides the intended use case for a given verification session
var useCase: ClearVerificationUseCase { get }
/// Provides the verification input type used to identify the member on which to perform an identity verification
var identifierInput: ClearVerificationIdentifierInput? { get }
/// Provides the result of a verification session in the form of a success or error.
/// A successful verification also provides an `authCode` and a `memberAsid`,
/// where an error will provide the reason for the error.
func verificationDidComplete(result: Result<ClearVerificationSuccess, ClearVerificationError>)
}
A ClearVerificationUseCase
represents the variety of use-cases that your app can declare as the purpose for a given verification session. Since you can implement multiple session instances throughout your app, it is also possible to support more than one use case. Although it is only possible to have one use case for each session. Your ClearVerificationSessionDelegate
should provide an intended use case, which will update the associated ClearVerificationView
descriptive label to match the descriptive intent of that use case.
public enum ClearVerificationUseCase {
/// Member identity verification and data sharing consent
case verifyWith
/// Partner authorization for account creation
case signupWith
/// Partner authorization for login
case loginWith
/// Venue and event admission using CLEAR (currently not supported)
case accessWith
/// Pay using the card on file with CLEAR (currently not supported)
case payWith
}
A ClearVerificationIdentifierInput
represents the initial parameters that determine the entry point for an identity verification flow. As such, there are two ways a partner app can specify initial verification input:
.email(ClearVerificationEmailInput)
: specifies a first-time identity verification via email.memberAsid("1234")
: specifies a returning identity verification, thereby bypassing the email collection screen and immediately forwarding a user to the camera screen for face capture/// Represents the two different kinds of identification input to determine the entry point for an identity verification flow.
public enum ClearVerificationIdentifierInput {
case email(input: ClearVerificationEmailInput)
case memberAsid(String)
}
ClearVerificationEmailInput
represents a variety of email configuration options required by the ClearVerificationIdentifierInput
.email()
option:
.editableEmail(nil)
: specifies a first-time identity verification, presenting an empty editable email input field.editableEmail(Email("hi@clearme.com"))
: specifies a first-time identity verification, presenting a pre-populated editable email input field (i.e. "hi@clearme.com").staticEmail(Email("hi@clearme.com"))
: specifies a first-time identity verification, presenting a pre-populated non-editable email input field (i.e. "hi@clearme.com").suppressedEmail(Email("hi@clearme.com"))
: specifies a first-time identity verification, though bypassing the email collection screen to the camera screen for face captureA ClearVerificationError
represents a successful verification result that includes an authCode
and a memberAsid
. The memberAsid
is an app-scoped member identifier that can be used instead of an email for a returning user flow. The authCode
can be exchanged for an access token in order to request additional information about a CLEAR member.
public struct ClearVerificationSuccess {
/// Code that can be exchanged for an access token
public let authCode: String
/// App-scoped member identifier
public let memberAsid: String
}
A ClearVerificationError
represents the various errors that can be returned from a session when a verification is unsuccessful.
public enum ClearVerificationError: Error {
/// The member email provided is invalid
case invalidEmail
/// The user failed to grant required permissions to the camera
case cameraSetupFailed
/// Member has exceeded the maximum number of allowed attempts (currently 10 per hour)
case accountLocked
/// Member has failed assurance
case failedAssurance
/// Member has either cancelled or abandoned the session
case userAbandoned
}
The SDK uses the device camera to validate members. Configure your App's Info.plist
file to include the NSCameraUsageDescription
. Provide a meaningful message that explains why your application is requesting this access.
Skipping this step will result in a crash.
The SDK uses Apple's DeviceCheck Framework to reduce fraudulent use of services.
iOS 14+ deployment targets must perform the following:
Add the capability App Attest
to your app in the developer portal
Certificates, Identifiers & Profiles
and find your application under Identifiers
App Attest
under Capabilities
Add App Attest Entitlement
to Xcode project
Signing & Capabilities
-> + Capability
App Attest
. This should add a .entitlements
file.entitlements
file to viewApp Attest Environment
from development
-> production
Step #2 is required for App Attestation
to run successfully for Debug
environment/schemes. More about Device Check Framework, App Attest Service and App Attest Environment
ClearVerificationView
cannot be used directly in Interface Builder due to Xcode limitations for embedded binaries. However, a container view could be added to the view hierarchy with ClearVerificationView
as a subview.
import UIKit
import ClearMeSDK
class VerificationViewController: UIViewController, ClearVerificationSessionDelegate {
@IBOutlet private var verificationViewContainer: UIView!
private lazy var clearVerificationView: ClearVerificationView = {
let view = ClearVerificationView(delegate: self)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
//Setup and Layout ClearVerificationView
verificationViewContainer.addSubview(clearVerificationView)
NSLayoutConstraint.activate([
clearVerificationView.topAnchor.constraint(equalTo: verificationViewContainer.topAnchor),
clearVerificationView.leadingAnchor.constraint(equalTo: verificationViewContainer.leadingAnchor),
clearVerificationView.trailingAnchor.constraint(equalTo: verificationViewContainer.trailingAnchor),
clearVerificationView.bottomAnchor.constraint(equalTo: verificationViewContainer.bottomAnchor),
])
}
// MARK: ClearVerificationSessionDelegate
var hostViewController: UIViewController { self }
var useCase: ClearVerificationUseCase { .verifyWith }
var identifierInput: ClearVerificationIdentifierInput? { .email(input: .editableEmail(try? .init("email@address.com")))}
func verificationDidComplete(result: Result<ClearVerificationSuccess, ClearVerificationError>) {
switch result {
case .success(let success):
// authCode can be exchanged for an access token
// memberAsid is the member's app-scoped identifier
print("auth code: \(success.authCode) | member asid: \(success.memberAsid)")
case .failure(let error):
print(error.localizedDescription)
}
}
}
If Interface Builder is not used, simply add the instance of ClearVerificationView
as a subview and set the constraints as required.
Coming soon...
link |
Stars: 0 |
Last commit: 5 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics