signInWithToken

abstract fun signInWithToken(token: String, host: String? = null, listener: Connection.ISignInListener? = null)

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

Parameters

token

The authentication token used for sign-in.

host

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

listener

Optional ISignInListener to receive callbacks for sign-in events. Set to null if not required.

Samples

import android.net.Uri
import com.ale.infra.rest.authentication.AuthenticationUrl
import com.ale.infra.rest.listeners.RainbowError
import com.ale.infra.rest.listeners.RainbowListener
import com.ale.rainbowsdk.Connection
import com.ale.rainbowsdk.RainbowSdk
import com.ale.security.util.HttpAuthorizationUtil
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()) {
    RainbowSdk().connection().signInWithToken(token, listener)
    return
}

RainbowSdk().connection().fetchUserAuthenticationUrls(loginEmail, listener = object : RainbowListener<AuthenticationUrl, Unit> {
    override fun onSuccess(data: AuthenticationUrl) {
        if (data.authenticationType == AuthenticationUrl.AuthenticationType.RAINBOW) {
            // No SSO configuration, user should login with email and password
            return
        }

        val uri = Uri.parse(data.loginUrl)
        val challenge = uri.getQueryParameter("challenge")
        HttpAuthorizationUtil.setAuthorizationChallenge(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")
    }

    override fun onError(error: RainbowError<Unit>) {
        // Handle error
    }
}) 
   //sampleEnd
}

abstract fun signInWithToken(token: String, listener: Connection.ISignInListener? = null)

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

Parameters

token

The authentication token used for sign-in.

listener

Optional ISignInListener to receive callbacks for sign-in events. Set to null if not required.