SudoUserClient
public protocol SudoUserClient : AnyObject
Protocol encapsulating a library of functions for calling Sudo Platform identity services, managing keys, performing cryptographic operations.
-
The release version of this instance of
SudoUserClient.Declaration
Swift
var version: String { get } -
isRegistered()AsynchronousIndicates whether or not this client is registered with Sudo Platform backend.
Declaration
Swift
func isRegistered() async throws -> BoolReturn Value
trueif the client is registered. -
reset()AsynchronousRemoves all keys associated with this client and invalidates any cached authentication credentials.
Throws
SudoUserClientError.FatalErrorDeclaration
Swift
func reset() async throws -
Registers this client against the backend with a registration challenge and validation data.
Declaration
Swift
func registerWithDeviceCheck( token: Data, buildType: String, vendorId: UUID, registrationId: String? ) async throws -> StringParameters
tokenApple DeviceCheck token..
buildTypeBuild type of the App from which the DeviceCheck token was retrieved, e.g. “debug” or “release”.
vendorIdAn alphanumeric string that uniquely identifies a device to the app’s vendor. Obtained via
identifierForVendorproperty ofUIDeviceclass.registrationIdThe registration ID used for uniquely identifying the registration request in case it fails.
Return Value
User ID of newly registered user.
-
Registers this client against the backend with an external authentication provider. Caller must implement
AuthenticationProviderprotocol to return appropriate authentication token required to authorize the registration request.Declaration
Swift
func registerWithAuthenticationProvider( authenticationProvider: AuthenticationProvider, registrationId: String? ) async throws -> StringParameters
authenticationProviderAuthentication provider that provides the authentication token.
registrationIdThe registrationId if known.
Return Value
User ID of newly registered user.
-
deregister()AsynchronousDeregisters this client from the backend and resets the keychain. Will throw an error if an error occurred while attempting to reset the keychain.
Declaration
Swift
func deregister() async throws -
resetUserData()AsynchronousRemoves all data owned by the signed-in user in Sudo Platform Services without deregistering the user. Should only be used in tests.
Declaration
Swift
func resetUserData() async throws -
signInWithKey()AsynchronousSign into the backend using a private key. The client must have created a private/public key pair via
registermethod.Declaration
Swift
func signInWithKey() async throws -> AuthenticationTokensReturn Value
Authentication tokens.
-
Sign into the backend with an external authentication provider. Caller must implement
AuthenticationProviderprotocol to return the appropriate authentication token associated with the external identity registered withregisterWithAuthenticationProvider.Declaration
Swift
func signInWithAuthenticationProvider(authenticationProvider: AuthenticationProvider) async throws -> AuthenticationTokensParameters
authenticationProviderAuthentication provider that provides the authentication token.
Return Value
Authentication tokens.
-
presentFederatedSignInUI(presentationAnchor:Default implementation, asynchronouspreferPrivateSession: ) Presents the sign in UI for federated sign in using an external identity provider.
Default Implementation
Declaration
Swift
func presentFederatedSignInUI(presentationAnchor: ASPresentationAnchor, preferPrivateSession: Bool) async throws -> AuthenticationTokensParameters
presentationAnchorWindow to act as the anchor for this UI.
preferPrivateSessionWill start the webUI sign in a private browser session, if supported by the current browser. Default:
true. This value internally setsprefersEphemeralWebBrowserSessionin ASWebAuthenticationSession. As per Apple documentation, whether the request is honored depends on the user’s default web browser. Safari always honors the request.Return Value
Authentication tokens.
-
presentFederatedSignOutUI(presentationAnchor:Asynchronous) Presents the sign out UI for federated sign in using an external identity provider.
Declaration
Swift
func presentFederatedSignOutUI(presentationAnchor: ASPresentationAnchor) async throwsParameters
presentationAnchorWindow to act as the anchor for this UI.
-
refreshTokens()AsynchronousRefreshes the access and ID tokens using the cached refresh token. The refresh token expires after 30 days so sign in again to obtain a new refresh token before its expiry. The tokens will also be refreshed automatically when you call platform APIs requiring authentication but there will be added delay in the API response. For more consistent response time for each API call, call this API to proactively keep the tokens fresh.
Declaration
Swift
func refreshTokens() async throws -> AuthenticationTokensReturn Value
Authentication tokens.
-
getUserName()AsynchronousReturns the user name associated with this client. The username maybe needed to contact the support team when diagnosing an issue related to a specific user.
Declaration
Swift
func getUserName() async throws -> StringReturn Value
User name.
-
getSubject()AsynchronousReturns the subject of the user associated with this client. Note: This is an internal method used by other Sudo platform SDKs.
Declaration
Swift
func getSubject() async throws -> String?Return Value
Subject.
-
getIdToken()AsynchronousReturns the ID token cached from the last sign-in. Note: This is an internal method used by other Sudo platform SDKs.
Declaration
Swift
func getIdToken() async throws -> StringReturn Value
ID token.
-
getAccessToken()AsynchronousReturns the access token cached from the last sign-in. Note: This is an internal method used by other Sudo platform SDKs.
Declaration
Swift
func getAccessToken() async throws -> StringReturn Value
Access token.
-
getRefreshToken()AsynchronousReturns the refresh token cached from the last sign-in. Use for callling
refreshTokensAPI to refresh the authentication tokens.Declaration
Swift
func getRefreshToken() async throws -> StringReturn Value
Refresh token.
-
clearAuthTokens()AsynchronousClears cached authentication tokens.
Declaration
Swift
func clearAuthTokens() async throws -
signOut()AsynchronousSigns out the user from this device only.
Declaration
Swift
func signOut() async throws -
globalSignOut()AsynchronousSigns out the user from all devices.
Declaration
Swift
func globalSignOut() async throws -
getIdentityId()AsynchronousRetrieves and returns the identity ID associated with the temporary credential used for accessing certain backend resources, e.g. large blobs stored in AWS S3.
Declaration
Swift
func getIdentityId() async throws -> StringReturn Value
Identity ID.
-
getUserClaim(name:Asynchronous) Returns the specified claim associated with the user’s identity.
Declaration
Swift
func getUserClaim(name: String) async throws -> Any?Parameters
nameClaim name.
Return Value
The specified claim value. The value can be of any JSON supported types. Safe cast it the expected Swift type before using it, e.g.
Dictionary,Array,String,NumberorBool. -
isSignedIn()AsynchronousIndicates whether or not the client is signed in. The client is considered signed in if it currently caches valid ID and access tokens.
Declaration
Swift
func isSignedIn() async throws -> BoolReturn Value
trueif the client is signed in. -
Returns the list of supported registration challenge types supported by the configured backend.
Declaration
Swift
func getSupportedRegistrationChallengeType() -> [ChallengeType]Return Value
List of supported registration challenge types.
-
registerSignInStatusObserver(id:Asynchronousobserver: ) Registers an observer for sign in status changes.
Declaration
Swift
func registerSignInStatusObserver(id: String, observer: SignInStatusObserver) asyncParameters
idunique ID to associate with the observer.
observersign in status observer to register.
-
deregisterSignInStatusObserver(id:Asynchronous) Deregisters an existing sign in status observer.
Declaration
Swift
func deregisterSignInStatusObserver(id: String) asyncParameters
idID of the observer to deregister.
SudoUserClient Protocol Reference