Microsoft Entra ID
Authentication

Tutorial Native Authentication Android Sign In After Sign Up

In brief

The tutorial documenting automatic user sign-in after Android native authentication sign-up, including error handling and Kotlin examples, was deleted.

What Entra admins need to know

Administrators supporting app teams should note that this reference is no longer available. No administrator action is specified.

This editorial summary was generated by AI from the documentation changes. Verify important details in the full Microsoft Learn article.

Documentation change

The comparison below shows only the changed extract. Use the full-page view for complete context.

deleted file mode 100644

title: Sign in user automatically after sign-up in Android by using native authentication description: Learn how to automatically sign-in a user after sign-up in an Android app by using native authentication.

manager: pmwongera

ms.service: identity-platform

ms.subservice: external ms.topic: tutorial ms.date: 03/20/2024 ms.custom: #Customer intent: As a dev, devops, I want to automatically sign in user after a sign-up flow by using native authentication so that I don't start a fresh sign-in flow.

Tutorial: Sign in user automatically after sign-up in an Android app

[!INCLUDE applies-to-external-only]

This tutorial demonstrates how to sign in user automatically after sign-up in an Android app by using native authentication.

In this tutorial, you:

[!div class="checklist"]

  • Sign in after sign-up.
  • Handle errors.

Prerequisites

Sign in after sign-up

After a successful sign-up flow, you can automatically sign in your users without initiating a fresh sign-in flow.

The SignUpResult.Complete returns SignInContinuationState object. The SignInContinuationState object provides access to signIn(parameters) method.

To sign up a user with email and password, then automatically sign them in, use the following code snippet:

CoroutineScope(Dispatchers.Main).launch {
    val parameters = NativeAuthSignUpParameters(username = email)
    parameters.password = password
    val actionResult: SignUpResult = authClient.signUp(parameters)

    if (SignUpActionResult is SignUpResult.CodeRequired) {
        val nextState = signUpActionResult.nextState
        val submitCodeActionResult = nextState.submitCode(
            code = code
        )
        if (submitCodeActionResult is SignUpResult.Complete) {
            // Handle sign up success
            val signInContinuationState = actionResult.nextState

            val parameters = NativeAuthSignInContinuationParameters()
            val signInActionResult = signInContinuationState.signIn(parameters)

            if (signInActionResult is SignInResult.Complete) {
                // Handle sign in success
                val accountState = signInActionResult.resultValue

                val getAccessTokenParameters = NativeAuthGetAccessTokenParameters()
                val accessTokenResult = accountState.getAccessToken(getAccessTokenParameters)

                if (accessTokenResult is GetAccessTokenResult.Complete) {
                    val accessToken = accessTokenResult.resultValue.accessToken
                    val idToken = accountState.getIdToken()
                }
            }
        }
    }
}

To retrieve ID token claims after sign-in, use the steps in Read ID token claims.

Handle sign-in errors

The SignInContinuationState.signIn(parameters) method returns SignInResult.Complete after a successful sign-in. It can also return an error.

To handle errors in SignInContinuationState.signIn(parameters), use the following code snippet:

val parameters = NativeAuthSignInContinuationParameters()
val signInActionResult = signInContinuationState.signIn(parameters)

when (signInActionResult) {
    is SignInResult.Complete -> {
        // Handle sign in success
         displayAccount(accountState = actionResult.resultValue)
    }
    is SignInContinuationError -> {
        // Handle unexpected error
    }
    else -> {
        // Handle unexpected error
    }
}

private fun displayAccount(accountState: AccountState) {
    CoroutineScope(Dispatchers.Main).launch {
        val getAccessTokenParameters = NativeAuthGetAccessTokenParameters()
        val accessTokenResult = accountState.getAccessToken(getAccessTokenParameters)
        if (accessTokenResult is GetAccessTokenResult.Complete) {
            val accessToken = accessTokenResult.resultValue.accessToken
            val idToken = accountState.getIdToken()
        }
    }
}

Next steps

Daily Entra.News

Get daily email updates

Get a concise summary of the latest Microsoft Entra updates delivered straight to your inbox.

Loading the secure signup form…