Hosted Authentication

Register or log in a user using a Passage Hosted Login page

Passage Hosted Authentication handles user authentication by opening a browser tab for login or sign-up. This simplifies the process, allowing Passage to manage the authentication seamlessly when users need access to your application.

See Add Passage for how to configure your app.

Configuration:

1. Set up App Linking in your app

Setting up App Linking will allow the Hosted Login to redirect your user back into your app after authorization to finish Passage authentication. Learn how to set up App Linking here.

Starting Hosted Authentication

To begin registering or logging in a user using a Hosted Authorization, simply call passage.hostedAuthStart(). Here is an example using Hosted Authorization:

passage.hostedAuthStart()

This will open up a secure web view where the user will be prompted to authorize your app.

Finish Authentication:

When the user has successfully authorized in the web view, they will be redirected into your app where you will receive an authorization code and state. You will use these code and state to finish authentication.

// In your Activity
override fun onNewIntent(intent: Intent?) {
  val authCode = intent.data?.getQueryParameter("code") ?: return
  val state = intent.data?.getQueryParameter("state") ?: return
  scope.launch {
      try {
          passage.hostedAuthFinish(authCode, state)
          // passage.getCurrentUser should now return the authenticated user
          val user = passage.getCurrentUser()
      } catch (e: FinishSocialAuthenticationException) {
          // Handle errors
      }
  }
}

Log out user

The secure hosted web view will keep your auth session until it expires. To clear the web view auth session and remove user's tokens from device, use passage.hostedLogout():

  passage.hostedLogout()

Last updated