iOS

This quickstart guide serves as an integration example for our trusted partners so that you will be able to test and/or evaluate LoginID’s authentication service for your own needs.

This document assumes that you are using Swift/Objective-C in your development environment.

Steps to follow

Useful APIs

  1. Login

  2. Logout

Create your client API keys

The first step to onboard yourself with LoginID is to create your client credentials. This allows your servers to call LoginID services in an authenticated fashion.

Install LoginID SDK for your Build Environment

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.

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 and then run pod install.

platform :ios, '10.0'
target 'MyTestObjcApp' do
use_frameworks!
#LoginSDK pod install
pod 'LoginSDK','0.85.23gh', :source => 'https://github.com/loginid1/LoginSDKSpecs.git'
# your other pods
end

Add NSFaceIDUsageDescription (Privacy - Face ID Usage Description) key/value to app's info.plist

This is a privacy description for accessing FaceID features on iOS. On devices with FaceID such as iPhoneX+, the user will be prompted with permission dialog based on this description about FaceID usage for the app.

<?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>

For Objective-C development, make sure to enable "Embed Swift Standard Libraries" in your build settings to avoid run-time error for objective-c

Build Settings > Build Options > Always Embed Swift Standard Libraries "YES"

Getting started with LoginID API SDK:

To see an overview of the iOS API SDK, please see:

Import LoginSDK Library

Swift
Objective-C
Swift
import LoginSDK
Objective-C
#import "LoginSDK/LoginSDK-Swift.h"

Configure LoginID API

This is the initialization process for our SDK allowing you to inject API keys through the SDK so LoginID can recognize you as a client.

First, you need to configure the SDK with your client API key and baseURL obtained from LoginID's developer console. This API must call before any other APIs. You should call this API within your AppDelegate's didFinishLaunchingWithOptions method.

ClientID and baseURL are generated by you on our dashboard when you create an iOS integration. Please refer to:

Swift
Objective-C
Swift
@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.sandbox.native-api.auth.loginid.id
let baseURL="<your base url"
LoginApi.client.configure(clientId: clientId, baseURL: baseURL)
...
...
}
...
...
Objective-C
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// clientId example 032690b3-9bc4-4602-87c1-60c1fae782f2
NSString * clientId=@"<your api key>";
// baseURL example 032690b3-9bc4-4602-87c1-60c1fae782f2.https://sandbox.api.auth.loginid.id
NSString * baseURL=@"<your baseURL>";
[LoginApi.client configureWithClientId:clientId baseURL:baseURL];
...
...
}
...
...

Getting User Account Information

Here is a set of functions for retrieving user information and login status.

Check if the user has an existing registered account:

Swift
Objective-C
Swift
// return true or false
let result = LoginApi.client.hasAccount()
Objective-C
// return YES or NO
BOOL result = [LoginApi.client hasAccount];

Get the current username:

Swift
Objective-C
Swift
// return username in string value
let username = LoginApi.client.getCurrentUsername()
Objective-C
// return username in string value
NSString * username = [LoginApi.client getCurrentUsername];

Check if the user has an active login session:

Swift
Objective-C
Swift
// return true or false
let result = LoginApi.client.isLoggedIn()
Objective-C
// return YES or NO
BOOL result = [LoginApi.client isLoggedIn]

Get current access token which is the latest JWT token returned by the server after a successful registered or verified API called:

The returned JWT indicates successful login or registration and can be used to give access to your users for certain activities of your choice, for example, access to a cloud file.

Swift
Objective-C
Swift
// return jwt in string value
let token = LoginApi.client.getCurrentToken()
Objective-C
// return jwt in string value
NSString * token = [LoginApi.client getCurrentToken]

Here is an example of how to use the above functionalities:

Swift
Objective-C
Swift
if(LoginApi.client.hasAccount()){
// get current username example
let username = LoginApi.client.getCurrentUsername()
// check if user has active login session
if(LoginApi.client.isLoggedIn()){
// get current token example
let token = LoginApi.client.getCurrentToken()
...
} else {
// can setup login user here
//present login option here
...
}
...
} else {
// user has no account so can setup register user logic here
...
}
Objective-C
if([LoginApi.client hasAccount]){
// get current username example
NSString * username = [LoginApi.client getCurrentUsername];
// check if user has active login session
if([LoginApi.client isLoggedIn]){
// get current token example
NSString * accessToken = [LoginApi.client getCurrentAccessToken];
...
} else {
// present login option here
...
}
} else {
// user has no account so can setup register user logic here
...
}

Register User Account

For an overview of LoginID registration flow of our API, please see:

Register an account with username specified

This API allows users to create new credentials with usernames via a FIDO2 registration. Having usernames registered will allow users to login by username from multiple platforms.

Swift
Objective-C
Swift
LoginApi.client.register(username: username, onComplete: { (response) in
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
print(response.errorMessage)
...
...
}
})
Objective-C
[LoginApi.client registerWithUsername:username onComplete:^(RegisterResponse * _Nonnull response) {
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
NSLog(response.errorMessage)
...
...
}
}];

Login or re-authenticate a registered account:

Once the user has successfully registered, LoginID will assign a JWT token to the response field. The token has a timestamp associate with it. You can ask the user to re-authenticate at any time afterward based on your business logic or if the token expired.

Swift
Objective-C
Swift
LoginApi.client.login(onComplete: { (response) in
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
print(response.errorMessage)
...
...
}
})
Objective-C
[LoginApi.client loginOnComplete:^(LoginResponse * _Nonnull response) {
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
NSLog(response.errorMessage)
...
...
}
}];

Login with username specified:

This API allows you to signed into a specific account. Use this in a scenario where you want to support multiple registered accounts on the same device.

Swift
Objective-C
Swift
// username passed from textfield input
LoginApi.client.login(username:useranme,onComplete: { (response) in
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
print(response.errorMessage)
...
...
}
})
Objective-C
// username passed from textfield input
[LoginApi.client loginWithUsername:username onComplete:^(LoginResponse * _Nonnull response) {
if(response.success){
// handle success case here
...
...
} else {
// handle error case here
NSLog(response.errorMessage)
...
...
}
}];

Logout

Call logout operation to invalidate the current access token.

Swift
Objective-C
Swift
LoginApi.client.logout()
Objective-C
[LoginApi.client logout];

All your credentials will be revoked once your app is deleted from your device.