Skip to main content

Login

If one or multiple users are already registered i.e. activated, StartResultEvent will have entries in its "userList". In case of multiple users, you need to choose the userIdentifier of the user you want to use to login. So, if StartResultEvent.userList.isNotEmpty() a LoginWithTokenEvent can be triggered in order to login. First we trigger a LoginWithTokenEvent with only the userIdentifier and authenticationMode as parameters. Note that in the KOBIL Digitanium+ environment, you can choose between several authentication modes for the login.

The MC manages all IAM tokens for us. So the MC will check if all needed token data for the user is available and if the tokens did not expire yet.

Activation and Login event flow diagram for Digitanium+

The following diagram depicts the event flow of the login process

iOS/Swift

For Swift, this check looks as follows:

First Login (Swift)
LoginWithTokenEvent(initWithoutParameters:
KsUserIdentifier(tenantId: tenantId,
userId: userId),
authenticationMode: .no)

Android/Kotlin

For Kotlin, here is the corresponding code:

First Login (Kotlin)
fun triggerLoginWithTokenEvent(userId: String, tenantId: String) {
val loginWithTokenEvent = LoginWithTokenEvent(
UserIdentifier(tenantId, userId),
AuthenticationMode.NO
)
mcEventHandler?.postEvent(loginWithTokenEvent)
}

All platforms

If the token data fulfills the expectations, the LoginWithTokenEvent will be successful and MC will send a LoginResultEvent with the status StatusType.OK as a response signaling a successful Login.

If the MC does not have the needed token data for the user (in the case of the first Login after activation) or if the saved tokens have expired, then the MC will respond with a LoginResultEvent having one of the following values as Status:

   StatusType.NO_TOKEN_DATA_AVAILABLE,
StatusType.CANNOT_ACQUIRE_ACCESS_TOKEN_FOR_AUTHORIZATION_CODE,
StatusType.CANNOT_ACQUIRE_AUTHORIZATION_CODE,
StatusType.CANNOT_ACQUIRE_TOKEN_DATA,
StatusType.TOKEN_DATA_IS_OUTDATED

In this case we need to redirect the user to the IAM login web page. After a successful login on the IAM web page, we will be able to extract an access token and an authorization code (exactly as explained in the activation section). Now we can trigger a LoginWithTokenEvent with the userIdentifier, authenticationMode, iamAccessToken and authorizationCode as parameters.

iOS/Swift

Here is how to do it in Swift:

Second Login (Swift)
fun triggerLoginWithTokenEvent(userId: String, tenantId: String,
accessToken: String, authCode: String) {
val loginWithTokenEvent = LoginWithTokenEvent(
UserIdentifier(tenantId, userId),
AuthenticationMode.NO,
accessToken,
authCode
)
masterControllerAdapter.sendEvent2MasterController(event,
withCompletionHandler: nil)
}

Android/Kotlin

Here is matching Kotlin code:

Second Login (Kotlin)
fun triggerLoginWithTokenEvent(userId: String, tenantId: String,
accessToken: String, authCode: String) {
val loginWithTokenEvent = LoginWithTokenEvent(
UserIdentifier(tenantId, userId),
AuthenticationMode.NO,
accessToken,
authCode
)
mcEventHandler?.postEvent(loginWithTokenEvent)
}

All platforms

The login should now be successful, the MC saves the needed token data for the user and we should get a LoginResultEvent with the status StatusType.OK from the MC.