# 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.

> [!NOTE]
> **Note:** If your app uses a sign-in method that Identity Platform supports (such as email and password), consider [migrating users](https://docs.cloud.google.com/identity-platform/docs/migrating-users.md.txt) instead of implementing custom authentication.

## Before you begin

- [Install the client SDK](https://docs.cloud.google.com/identity-platform/docs/quickstart-email-password).

- Configure your server to accept user credentials and
  [mint custom tokens](https://docs.cloud.google.com/identity-platform/docs/admin/create-custom-tokens.md.txt).

## 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()`](https://docs.cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/signInWithCustomToken.md.txt)
   to authenticate the user with Identity Platform:

   ### Web version 9

   ```javascript
   import { getAuth, signInWithCustomToken } from "firebase/auth";

   const auth = getAuth();
   signInWithCustomToken(auth, token)
     .then((userCredential) => {
       // Signed in
       const user = userCredential.user;
       // ...
     })
     .catch((error) => {
       const errorCode = error.code;
       const errorMessage = error.message;
       // ...
     });
   ```

   ### Web version 8

   ```javascript
   firebase.auth().signInWithCustomToken(token)
     .then((userCredential) => {
       // Signed in
       var user = userCredential.user;
       // ...
     })
     .catch((error) => {
       var errorCode = error.code;
       var errorMessage = error.message;
       // ...
     });
   ```

# What's next

- [Configure custom claims](https://docs.cloud.google.com/identity-platform/docs/how-to-configure-custom-claims.md.txt) on users.
- [Use the REST API](https://docs.cloud.google.com/identity-platform/docs/use-rest-api.md.txt) to integrate Identity Platform with other parts of your custom authentication system.