Identity Platform を使用してユーザーがメールアドレスでログインできるようにする

Identity Platform を使用してメールアドレスとパスワードでユーザーのログインを行う方法を学習します。


このタスクを Google Cloud コンソールで直接行う際の順を追ったガイダンスについては、「ガイドを表示」をクリックしてください。

ガイドを表示


始める前に

  1. Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、 アカウントを作成して、実際のシナリオでの Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Make sure that you have the following role or roles on the project: Identity Platform Admin, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Make sure that you have the following role or roles on the project: Identity Platform Admin, Service Usage Admin

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.

Identity Platform を有効化

  1. Google Cloud コンソールで、Cloud Marketplace の [Identity Platform] ページに移動します。

    Identity Platform に移動

  2. [IDENTITY PLATFORM を有効化] をクリックします。

メール ログインを構成する

  1. [ID プロバイダ] ページに移動します。

    [ID プロバイダ] に移動

  2. [ID プロバイダ] ページで [プロバイダを追加] をクリックします。

  3. [プロバイダの選択] リストで、 [メール / パスワード] を選択します。

  4. [Enabled] をオンに切り替えます。

  5. プロバイダの設定を保存するには、[保存] をクリックします。

ユーザーを作成する

  1. Google Cloud コンソールで、[ユーザー] ページに移動します。

    [ユーザー] に移動

  2. [ユーザーを追加] をクリックします。

  3. [メール] フィールドにメールアドレスを入力し、下のフィールドにパスワードも入力します。後の手順で必要になるため、両方の値をメモします。

  4. ユーザーを追加するには、[追加] をクリックします。新しいユーザーが [ユーザー] ページに表示されます。

ユーザーのログインを行う

ユーザーのログイン手順は、アプリが使用している SDK のバージョンによって異なります。

アプリケーションの正しい手順に従ってください。

SDK v9(モジュール式)

SDK をインストールして Firebase を初期化する

Firebase JS SDK バージョン 9 では、JavaScript モジュールの形式を使用します。

このワークフローでは npm を使用します。v9 SDK は、ツリー シェイキングで未使用コードを削除して SDK のサイズを小さくするために、モジュール バンドラと連携するように最適化されています。このため、モジュール バンドラまたは JavaScript フレームワーク ツールを使用する必要があります。

v9 SDK を使用するには、次の手順を行います。

  1. プロジェクト ディレクトリから、npm を使用して Firebase をインストールします。