Skip to main content

iOS

Initial Setup

The LoginID iOS SDK enables you to add FIDO-certified authentication in your native iOS application without having to redirect the user to any pages outside your application.

For more robust functionality, it is likely that you will need to also leverage a Server SDK. The Server SDK makes requests to LoginID's API easier by leveraging your API Credential. Check out the LoginID Server SDK for a simplified integration.

Create Application on the Dashboard

An application must be created on the LoginID Dashboard in order to correctly configure the iOS SDK.

Once logged into the dashboard, navigate to the Applications tab in the sidebar, select “Add Application,” then select “Mobile”.

In the resulting form, you must create a name for your application. A Client ID and Base URL for your application are generated that are needed to configure the SDK.

After entering your application name, you will be prompted to create an API credential. For mobile applications, please skip this step. Otherwise, create an API credential in order to make protected API calls.

note

An API service token must be included on all requests once an API credential is assigned to an application.

Add SDK to Existing Application

This instruction is for configuring your Xcode environment using Cocoapods (Please refer to https://cocoapods.org/ for more information). The LoginID SDK requires min iOS 10 for compatibility.

note

This SDK requires biometrics with a secure enclave that is only available on actual devices with iOS 10 +. Simulated devices are not currently supported.

Add Login SDK framework to your Podfile, then run pod install.

platform :ios, '10.0'

target 'MyTestObjcApp' do
use_frameworks!
#LoginSDK pod install
pod 'LoginSDK','0.90.31', :source => 'https://github.com/loginid1/LoginSDKSpecs.git'
# your other pods

end
note

iOS mandates adding a usage string with the key NSFaceIDUsageDescription to your app’s info.plist file in order to use FaceID.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSFaceIDUsageDescription</key>
<string>Privacy description regarding to usage of FaceID feature</string>
...
...
</plist>

Note: For Objective-C development, make sure to enable "Embed Swift Standard Libraries" in your build settings to avoid a runtime error

Enable this functionality by navigating to: Build Settings > Build Options > Always Embed Swift Standard Libraries "YES"

Create an SDK Instance

import LoginIDSDK

The LoginID API must be called before any other APIs. You should call this API within your AppDelegate's didFinishLaunchingWithOptions method.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// clientId example 032690b3-9bc4-4602-87c1-60c1fae782f2
let clientId="<your api key>"
// baseURL example https://060ce487-b934-43d0-a925-b66e80c7532f.native-api.auth.loginid.id
let baseURL="<your base url"

LoginApi.client.configure(clientId: clientId, baseURL: baseURL)
...
...
}
...
...

API Reference

Create an SDK Instance

import LoginIDSDK

The LoginID API must be called before any other APIs. You should call this API within your AppDelegate's didFinishLaunchingWithOptions method.

""
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// clientId example 032690b3-9bc4-4602-87c1-60c1fae782f2
let clientId="<your api key>"
// baseURL example https://060ce487-b934-43d0-a925-b66e80c7532f.native-api.auth.loginid.id
let baseURL="<your base url"

LoginApi.client.configure(clientId: clientId, baseURL: baseURL)
...
...
}
...
...

registerWithFido2

Sign up a user for FIDO authentication.

@objc(registerWithFido2:options:onComplete:) public func registerWithFido2(username: String?, options: RegistrationOptions?, onComplete: @escaping(RegisterResponse)->Void)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be registered.
optionsRegistrationOptionsoptionalAPI Service token signed by your Private Key, as per the API Credential added to the integration. RegistrationOptions.buildAuth(token: authToken)
onComplete@callbacktrueCallback function to handle returning results (RegisterResponse)

registerWithPassword

Creates a user account with a password (not recommended). If leveraging this method, users should be migrating to use a FIDO authenticator, then have their password revoked.

@objc (registerWithPassword:password:confirmPassword:options:onComplete:) public func registerWithPassword(username:String, password: String, confirmPassword:String, options: RegistrationOptions?, onComplete: @escaping(RegisterResponse)->Void)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be registered.
passwordstringtruePassword of the customer to be registered.
passwordConfirmationstringtrueIt is best practice to have the customer enter their password twice before creating their profile to prevent typos. If desired, you could only require the end user to enter their password once and pass that password in both fields.
optionsRegistrationOptionsoptionalAPI Service token signed by your Private Key, as per the API Credential added to the integration. RegistrationOptions.buildAuth(token: authToken)
onComplete@callbacktrueCallback function to handle returning results (RegisterResponse)

authenticateWithFido2

Authenticate a previously registered user through FIDO2.

@objc(authenticateWithFido2:options:onComplete:) public func authenticateWithFido2(username: String, options: AuthenticationOptions?, onComplete: @escaping(AuthenticateResponse)->Void)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be authenticated.
optionsAuthenticationOptionsoptionalAPI Service token signed by your Private Key, as per the API Credential added to the integration. AuthenticationOptions.buildAuth(token: authToken)
onComplete@callbacktrueCallback function to handle returning results (AuthenticateResponse)

authenticateWithPassword

Authenticate a previously registered user using username and password.

@objc (authenticateWithPassword:password:options:onComplete:) public func authenticateWithPassword(username:String, password: String, options: AuthenticationOptions?, onComplete: @escaping(AuthenticateResponse)->Void)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to be authenticated.
passwordstringtruePassword of the customer to be authenticated.
optionsAuthenticationOptionsoptionalAPI Service token signed by your Private Key, as per the API Credential added to the integration. AuthenticationOptions.buildAuth(token: authToken)
onComplete@callbacktrueCallback function to handle returning results (AuthenticateResponse)

confirmTransaction

@objc(transactionConfirmation:payload:options:vieController:onComplete:) public func transactionConfirmation(username: String, payload: TransactionPayload, options: TransactionOptions?, viewController: UIViewController, onComplete:@escaping(TransactionConfirmationResponse)->Void)

| username | string | true | Username of the customer confirming the transaction. | | payload | TransactionPayload | true | Require a client side generated nonce value and a text message to display back to user for confirmation TransactionPayload.buildText(nonce: nonce, data: payload) | | options | AuthenticationOptions | optional | API Service token signed by your Private Key, as per the API Credential added to the integration. AuthenticationOptions.buildAuth(token: authToken) | | viewController | UIViewController | true | The presenting view controller where the transaction is called from | | onComplete | @callback | true | Callback function to handle returning results (TransactionConfirmationResponse)|

addFido2Credential

Adds a FIDO2 credential type to the account. Can be used to recover an account or add another device to the same username.

@objc (addFido2Credential:code:options:onComplete:) public func addFido2Credential(username: String?, code: String, options: AddCredentialOptions?, onComplete: @escaping(AddCredentialResponse)->Void)

ParameterTypeRequiredDetails
usernamestringtrueUsername of the customer to adding a FIDO2 credential.
codestringtrueThe short OTP code required to initiate adding the FIDO2 credential.
optionsAddCredentialOptionsoptionalAPI Service token signed by your Private Key, as per the API Credential added to the integration. \AddCredentialOptions.buildAuth(token: authToken)
onComplete@callbacktrueCallback function to handle returning results (AddCredentialResponse)

isLoggedIn

Check if a given user is currently logged in.

logout

Deprecated Methods

The iOS SDK previously had the following methods:

  • .register()
  • .login()

The methods have been deprecated, as the type of authenticator is now specified in the register and authenticate methods.