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.

Hosted authentication example

Configuration

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.hosted.start. Here is an example using Hosted Authorization:

passage.hosted.start()

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.hosted.finish(authCode, state)
          // passage.getCurrentUser should now return the authenticated user
          val user = passage.currentUser.userInfo() ?: return
          // Do authenticated stuff
      } catch (e: HostedAuthorizationError) {
          // Handle errors
      }
  }
}