OpenPass SDK for iOS and tv OS reference
For background information on the OpenPass service, and general information on implementation, see Getting started with OpenPass.
This SDK uses the following iOS and tvOS structs, classes, and extensions for the OpenPass client.
Structs
ID token
public struct IDToken: Codable
A codable OIDC ID token data object. For details, see the OpenID spec.
Properties
The following is a list of the ID token properties.
| Name | Code | Description |
|---|---|---|
keyId |
public let keyId: String |
ID of the key used to sign the token. |
tokenType |
public let tokenType: String |
Type of token. |
algorithm |
public let algorithm: String |
Signing algorithm used. |
issuerIdentifier |
public let issuerIdentifier: String |
Issue identifier for the ID token. |
subjectIdentifier |
public let subjectIdentifier: String |
Subject identifier for the ID token. |
audience |
public let audience: String |
Audience for the ID token. |
expirationTime |
public let expirationTime: Int64 |
Expiration time for the ID token in milliseconds. |
issuedTime |
public let issuedTime: Int64 |
Time the ID token was issued at in milliseconds. |
email |
public let email: String? |
Email address provided by the user. |
given_name |
public let givenName: String? |
The given or first name of the end user. Here are key points:
|
family_name |
public let familyName: String? |
The surname or last name of the end user. Here are key points:
|
The following is the method used by the ID token.
Method
public init?(idTokenJWT: String)
The following method and its parameters construct the ID token as a JSON Web Token (JWT).
| Name | Description |
|---|---|
idTokenJWT |
The ID token as a JWT. |
OpenPass Tokens
public struct OpenPassTokens: Codable
A codable data object for OpenPass ID and access tokens.
Properties
The following is a list of the OpenPass token properties.
| Name | Code | Description |
|---|---|---|
idToken |
public let idToken: IDToken? |
ID token constructed through the idTokenJWT method. |
idTokenJWT |
public let idTokenJWT: String |
ID token as a JWT. |
accessToken |
public let accessToken: String |
The access token. |
tokenType |
public let tokenType: String |
Type of access token. |
expiresIn |
public let expiresIn: Int64 |
Expiration time of the token in UTC. |
The following is the method used by OpenPass tokens.
Method
init(idTokenJWT:accessToken:tokenType:expiresIn:)
public init(idTokenJWT: String, accessToken: String, tokenType: String, expiresIn: Int64)
The following are parameters for initializing the OpenPass token.
| Parameter | Description |
|---|---|
idTokenJWT |
ID Token as a JWT. |
accessToken |
The access token. |
tokenType |
The type of access token. |
expiresIn |
Expiration time of the token in UTC. |
Classes
OpenPass Manager
public final class OpenPassManager: NSObject
The primary app interface for integrating with OpenPass SDK.
Properties
| Name | Code | Description |
|---|---|---|
shared |
public static let shared = OpenPassManager() |
Singleton access point for the OpenPass manager. |
openPassTokens |
public private(set) var openPassTokens: OpenPassTokens? |
User data for the OpenPass user who is currently signed in. |
sdkVersion |
public let sdkVersion = "1.1.0" |
The SDK version of OpenPass. |
Methods
The following are methods used by OpenPass tokens.
| Method | Code | Description |
|---|---|---|
beginSignInUXFlow() |
public func beginSignInUXFlow() async throws -> OpenPassTokens |
Starts the OpenID Connect (OAuth) authentication user interface flow. Returns authenticated OpenPass tokens. |
signOut() |
public func signOut() -> Bool |
Signs the user out by clearing all sign-in data currently in the SDK, including key chain and in-memory data. Returns True if signed out, or False if still signed in. |
deviceAuthorizationFlow |
public var deviceAuthorizationFlow: DeviceAuthorizationFlow |
Returns a `DeviceAuthorizationFlow object for performing device authorization. |
The following are methods used by the device authorization flow.
| Method | Code | Description |
|---|---|---|
fetchDeviceCode() |
public func fetchDeviceCode() async throws -> DeviceCode |
Initiates the device authorization flow by fetching and returning a device code. |
fetchAccessToken() |
public func fetchAccessToken(deviceCode: DeviceCode) async throws -> OpenPassTokens |
Fetches access tokens and polls them until authorization is granted. Returns OpenPassTokens. |
Extensions
OpenPass Manager
extension OpenPassManager: ASWebAuthenticationPresentationContextProviding
Method
presentationAnchor(for:)
public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor
An Apple-provided API for telling the delegate which window it should use to present content to the user. Its parameter session is the current session used to perform authentication. The method returns the ASPresentationAnchor type for the system to display the ASWebAuthenticationSession session.
| Parameter | Description |
|---|---|
session |
Current session used to perform authentication. |
OpenPass tokens
extension OpenPassTokens
The following are methods used by OpenPass tokens.
| Method | Code | Description |
|---|---|---|
toData() |
public func toData() throws -> Data |
Returns OpenPassTokens as data. |
fromData(_:) |
public static func fromData(_ data: Data) -> OpenPassTokens? |
A data representation of OpenPassTokens that returns OpenPassTokens if the decoding is successful, or nil if it is not successful. |