Quickstart: Sign in users with email and password

This quickstart shows you how to use Identity Platform to sign in a user with an email and password.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Enable Identity Platform

  1. Go to the Identity Platform Marketplace page in the Cloud Console.

    Go to the Identity Platform Marketplace page

  2. Click Enable Identity Platform. The Identity Platform page appears in the Cloud Console.

Configure email sign-in

  1. Go to the Identity Providers page in the Cloud Console.

    Go to the Identity Providers page

  2. Click Add A Provider.

  3. Select Email/Password from the list of providers and enterprise federation standards.

  4. Toggle the Enabled switch to On.

  5. Click Save.

Create a user

  1. Go to the Users page in the Cloud Console.

    Go to the Users page

  2. Click Add user.

  3. Enter an email and password.

  4. Click Save. The new user appears in the users list.

Sign the user in

  1. Create a new file named index.html.

  2. Add two basic HTML containers:

    <div>Identity Platform Quickstart</div>
    <div id="message">Loading...</div>
    
  3. Initialize the Identity Platform Client SDK with your API key:

    1. Go to the Identity Providers page in the Cloud Console.

      Go to the Identity Providers page

    2. Click Application setup details.

    3. Copy the initialization code into index.html. It should look something like:

      <script src="https://www.gstatic.com/firebasejs/8.1.1/firebase.js"></script>
      <script>
        // Initialize Identity Platform
        var config = {
          apiKey: "abcdefg123456",
          authDomain: "myproject.firebaseapp.com"
        };
        firebase.initializeApp(config);
      </script>
      
  4. Sign the user in by calling signInWithEmailAndPassword(), and then process the result with the onAuthStateChanged() callback. In the example below, replace email and password with the values for the user you created earlier:

    <script>
      var email = "example@gmail.com";
      var password = "hunter2";
    
      firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
          document.getElementById("message").innerHTML = "Welcome, " + user.email;
        } else {
          document.getElementById("message").innerHTML = "No user signed in.";
        }
      });
    
      firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
        document.getElementById("message").innerHTML = error.message;
      });
    </script>
    
  5. Launch index.html in your web browser. A welcome message displaying your user's email appears.

Congratulations! You've signed your first user in with Identity Platform.

What's next

In a real app, your users would sign up using a dedicated registration page, and sign in by entering their emails and passwords. Identity Platform offers a pre-built authentication UI you can use for these pages, or you can build your own. You might also want to support additional sign-in methods, such as social providers (like Facebook or Google), phone numbers, OIDC, or SAML.

Learn more about how to: