Skip to main content

Identity Integration in IOS

Description#

Trust is a platform that allows building trust and security between people and technology.

TrustDeviceInfo allows you to obtain a unique universal ID for each device from a set of characteristics of this device. It also allows the monitoring of device status changes, to have knowledge of the device status at all times.

Implementation#

Add in your podfile:

platform :ios, '13.0'
use_frameworks!
target 'AppName' do
pod 'TrustDeviceInfo', :git => 'https://gitlab.com/trustchile/ios-public-frameworks/trustdeviceinfo-xcframework.git', :tag => '2.10.4'
end

And execute:

pod install

Initialize#

Generate a new TrustID:#

AccessGroup: To generate a new accessGroup you need to activate your keychain sharing capability in Signing & Capabilities, you must also be part of an Apple development group to access to its identifier to generate your access group.

Team ID: Found it in https://developer.apple.com/

  • accessGroup structure: "teamID.keychainName.id". (Team ID can be found here)
  • accessGroup example: "example.access.group"
  • clientID and clientSecret are generated in backend, so you must request access codes to the provider.

Methods#

Enable TrustDeviceInfo#

Enables TrustDeviceInfo device information access

TrustDeviceInfo.shared.enable()

Get access token#

Asks for credentials to access Trust Identification services

TrustDeviceInfo.shared.createClientCredentials(clientID: clientID, clientSecret: clientSecret, completion: nil)

Get Trust ID#

Returns the device Trust ID

TrustDeviceInfo.shared.getTrustID()

Set Current environment (.prod or .test)#

Sets the current working environment for TrustDeviceInfo

TrustDeviceInfo.shared.set(currentEnvironment: .prod)

Set ServiceName and AccessGroup for Keychain Access#

Sets the ServiceName and AccessGroup to safely save and fetch values from the Keychain

TrustDeviceInfo.shared.set(serviceName: serviceName, accessGroup: accessGroup)

Register Identity#

  • Consider call replacing with the user identity DNI. Example: Identify.shared.setAppState(dni: "11.111.111-1")
  • TrustDeviceInfo.shared.sendDeviceInfo(identityInfo: userIdentity)
    • userIdentity must need to be: IdentityInfoDataSource protocol type

Set App State#

Sets the app identification state. You should call this method when your app finishes the current user session checking, if there's an active session you should send the dni of current user as parameter

TrustDeviceInfo.shared.setAppState(dni: userDni)

If no user logged in you should use

TrustDeviceInfo.shared.setAppState()

Send Device Info#

Sends the device hardware information to Trust Identification services and optionally sends the identity of current user (if any)

let userIdentity = IdentityInfo(
dni: "11.111.111-1",
name: "First name",
lastName: "Last name",
email: "example@example.com",
phone: "9099909909",
appleUserId: "appleUserId"
)
TrustDeviceInfo.shared.sendDeviceInfo(identityInfo: userIdentityInfo)

otherwise you can provide only the default data by calling

TrustDeviceInfo.shared.sendDeviceInfo()

Delete Trust ID#

Removes the device generated TrustID

TrustDeviceInfo.shared.deleteTrustID()

Implementation Example#

import TrustDeviceInfo
extension AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
setupTrustDeviceInfo()
return true
}
}
extension AppDelegate {
func setupTrustDeviceInfo() {
TrustDeviceInfo.shared.enable()
TrustDeviceInfo.shared.set(currentEnvironment: .prod)
TrustDeviceInfo.shared.set(serviceName: Bundle.main.bundleIdentifier ?? "EXAMPLE.BUNDLE.ID", accessGroup: "<APPLE-DEVELOPER-TEAM-ID>.<KEYCHAIN-GROUP-ID>")
TrustDeviceInfo.shared.createClientCredentials(
clientID: .AppCredentials.clientId,
clientSecret: .AppCredentials.clientSecret
) {
// From this point the trust id is available
TrustDeviceInfo.shared.getTrustID()
// Here you can safely execute methods that require access token authorization
sendDeviceState()
}
}
func sendDeviceState() {
guard let currentUserDni = currentUserManager.getUserDni() else { TrustDeviceInfo.shared.setAppState(); return }
TrustDeviceInfo.shared.setAppState(dni: currentUserDni)
}
}

Permissions#

As mentioned above, we must activate the keychain sharing capability and set our new "Keychain Group"

NOTE: Remember your keychain groups to share information between apps with the same team ID.

Last updated on by fcaro