Links

iOS mobile SDK

Implement Strivacity sign-in journeys into your brand's iOS mobile app using web views and Strivacity's Authentication APIs.
The Strivacity Mobile SDK for iOS provides a simple client for communicating with Strivacity Authentication APIs

Download

This SDK is available through the CocoaPods. To install it, simply add the following line to your Podfile:
pod 'Strivacity'

Demo App

A demo app is contained within the Strivacity Github Repository. For instructions on how to build and configure this app, see its ReadMe file.

Overview

The internal implementation of the Strivacity SDK for iOS relies on the open-source AppAuth Library.
Strivacity SDK incapsulates logic of communication with Strivacity Authentication APIs in the AuthClient class and its members. AuthProvider class creates AuthClient and sets it up with specified parameters.
For a convenient representation of the authorization state with the ability to serialize to JSON uses class AuthState from AppAuth Library.
To store the authentication state securely, use the class SecureStorage, which saves auth state to the default iOS Keychain.

Initialize AuthProvider

First, specify an AuthProvider class to create AuthClient instance. For example:
let authProvider = AuthProvider()
authProvider.withClientId(Bundle.main.object(forInfoDictionaryKey: clientIdKey) as? String ?? "") // specifies app client id
authProvider.withClientSecret(Bundle.main.object(forInfoDictionaryKey: clientSecretKey) as? String ?? "") // specifies app client secret
authProvider.withDomain(Bundle.main.object(forInfoDictionaryKey: domainKey) as? String ?? "") // specifies authentication server domain
authProvider.withRedirectUri(Bundle.main.object(forInfoDictionaryKey: redirectUriKey) as? String ?? "") // specifies authorized redirect uri
authProvider.withAuthState(authState) // specifies default auth state
authProvider.setUseSecureStorage(true) // specifies using SecureStorage for saving auth state between app launches
authProvider.setUseBiometric(EBiometricType.any) // specifies biometric usage

Features of initialization:

In order to initialize AuthClient object with particular AuthState, it can be passed to AuthProvider object.
authProvider.withAuthState(authState) // specifies default auth state
In other case do not call this command.
Also the default iOS Keychain usage by AuthClient can be specified:
authProvider.setUseSecureStorage(true) // specifies SecureStorage usage for saving auth state between app launches
In order to avoid storing auth state in Keychain, please pass false to this method.
Biometric verification for access data in SecureStorage also can be specified:
authProvider.setUseBiometric(EBiometricType.any) // specifies biometric usage
In order to disable biometric authentication, please pass EBiometricType.none to this method.

Provide AuthClient

To obtain the AuthClient instance, you need to call authProvider.provide() method and pass into it an object which has implemented the IProviderCallback interface methods.
public protocol IProviderCallback {
/**
* Invoked after successful [AuthClient] creation.
*/
func onSuccess(authClient: AuthClient)
/**
* Invoked after completion with error of the [AuthClient] creation.
*/
func onError(error: NSError)
}

Examples of performing Strivacity Authentication APIs via AuthClient:

Begin an OIDC Authorization Code Flow:

authClient.authorizeAuthCodeFlow(viewController: self, completion: { result in
// result has type Result<AnyObject, Error> and can have AuthState object with auth code on success or Error on failure
})

Obtain an ID Token from an Authorization Code which has been previously obtained via the Authorization Code Flow:

authClient.requestIdToken(viewController: self, completion: { result in
// result has type Result<AnyObject, Error> and can have AuthState object with auth code, access token and id token on success or Error on failure
})

Begin an OIDC Hybrid Flow:

authClient.authorizeHybridFlow(viewController: self, completion: { result in
// result has type Result<AnyObject, Error> and can have AuthState object with auth code, access token and id token on success or Error on failure
})

Begin an OIDC RP Initiated Logout:

authClient.logout(viewController: self, completion: logoutCompletion(_:))
// logoutCompletion function has the argument of type Result<Bool, Error> and can have Boolean value on success or Error on failure

Obtain an Access Token via Client Credentials:

authClient.requestAccessToken(viewController: self, completion: { result in
// result has type Result<AnyObject, Error> and can have AuthState object with access token on success or Error on failure
})
For detailed documentation of classes, enumerations, extensions, protocols, and structures, see our extended Mobile SDK for iOS documentation.