Signing in users with a custom authentication system

This document shows you how to use Identity Platform to sign in users with a custom authentication system. In custom authentication, you use an authentication server to produce custom signed tokens when a user successfully signs in. Your app receives this token and uses it to authenticate with Identity Platform.

Before you begin

Signing in users

  1. Collect sign-in credentials from the user.

  2. Send the credentials to your server. Your server validates the request, and returns a custom JWT.

  3. Pass the JWT to signInWithCustomToken() to authenticate the user with Identity Platform:

    Web version 9

    import{getAuth,signInWithCustomToken}from"firebase/auth";
    constauth=getAuth();
    signInWithCustomToken(auth,token)
    .then((userCredential)=>{
    // Signed in
    constuser=userCredential.user;
    // ...
    })
    .catch((error)=>{
    consterrorCode=error.code;
    consterrorMessage=error.message;
    // ...
    });

    Web version 8

    firebase.auth().signInWithCustomToken(token)
    .then((userCredential)=>{
    // Signed in
    varuser=userCredential.user;
    // ...
    })
    .catch((error)=>{
    varerrorCode=error.code;
    varerrorMessage=error.message;
    // ...
    });

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月17日 UTC.