signInWithToken

abstract suspend fun signInWithToken(token: String, host: String? = null): RainbowResult<Unit>

Initiates a sign-in process using the provided authentication token and an optional custom host URL.

Return

RainbowResult to receive callbacks for sign-in events.

Parameters

token

The authentication token used for sign-in.

host

Optional custom host URL for authentication. Set to null for default configuration.

Samples

import android.net.Uri
import com.ale.infra.rest.authentication.AuthenticationUrl
import com.ale.infra.rest.listeners.onFailure
import com.ale.infra.rest.listeners.onSuccess
import com.ale.rainbowsdk.Connection
import com.ale.rainbowsdk.RainbowSdk
import com.ale.security.util.HttpAuthorizationUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

fun main() { 
   //sampleStart 
   if (RainbowSdk().connection().state != Connection.ConnectionState.DISCONNECTED) {
    // User is already authenticating or authenticated
    return
}

// The user has already logged in, the existing token can be used
val token = RainbowSdk().user().userTokenInCache

if (token.isNotEmpty()) {
    CoroutineScope(Dispatchers.Main).launch {
        RainbowSdk().connection().signInWithToken(token)
    }
    return
}

CoroutineScope(Dispatchers.Main).launch {
    RainbowSdk().connection().fetchUserAuthenticationUrls(loginEmail).onSuccess { data ->
        if (data.authenticationType == AuthenticationUrl.AuthenticationType.RAINBOW) {
            // No SSO configuration, user should login with email and password
            return@onSuccess
        }

        val uri = Uri.parse(data.loginUrl)
        val challenge = uri.getQueryParameter("challenge")
        HttpAuthorizationUtil.authorizationChallenge = challenge
        val loginUrl = data.loginUrl + "&x-rainbow-app-auth=" + HttpAuthorizationUtil.makeAuthorizationSAMLUrlString()

        // Load URL inside a custom tabs or an external WebView
        // ...
        // Once the token has been obtained
        RainbowSdk().connection().signInWithToken("token")
    }.onFailure {
        // Handle error
    }
} 
   //sampleEnd
}

abstract suspend fun signInWithToken(token: String): RainbowResult<Unit>

Initiates a sign-in process using the provided authentication token.

Return

RainbowResult to receive callbacks for sign-in events.

Parameters

token

The authentication token used for sign-in.