amplify add auth をマニュアルセットアップをしてみて何を聞かれるか見てみる
amplify add authを実行すると出てくる選択肢。今回はこの選択肢からマニュアルセットアップを選択した時に何が聞かれるのかみていきましょう!
$ amplify add auth
このコマンドを実行すると選択肢が出てきます。今回はManual configurationを選択していきます。
Using service: Cognito, provided by: awscloudformation
The current configured provider is Amazon Cognito.
Do you want to use the default authentication and security configuration?
Default configuration
Default configuration with Social Provider (Federation)
❯ Manual configuration
I want to learn more.
Select the authentication/authorization services that you want to use: (Use arrow keys)
❯ User Sign-Up, Sign-In, connected with AWS IAM controls (Enables per-user Storage features for images or other content, Analytics, and more)
User Sign-Up & Sign-In only (Best used with a cloud API only)
最初の設問は、認証 (auth) 機能を設定する際に、どのようなサービスを有効化するかを決めるものです。
User Sign-Up, Sign-In, connected with AWS IAM controlsはユーザーのサインアップ・サインイン機能に加え、AWS IAM(Identity and Access Management)を通じて追加の権限管理を行います。
User Sign-Up & Sign-In onlyはユーザーのサインアップ・サインイン機能だけを有効化し、IAM を使用しないシンプルな認証です。
Provide a friendly name for your resource that will be used to label this category in the project: (xxxxxxxxx3e61e0797e61e0797)
AWS Amplifyで「Auth」カテゴリを設定する際に、そのリソースのフレンドリーネーム(friendly name)を指定するよう求めています。この名前は、主にプロジェクト内でリソースを識別しやすくするためのラベルとして使われます。
デフォルトではランダムな文字列(例: xxxxxxxxx3e61e0797e61e0797)が提案されますが、これは自由に変更可能です。
Enter a name for your identity pool. (xxxxxxxxx3e61e0797_identitypool_e61e0797)
この質問では、Cognito Identity Poolの名前を指定するよう求められています。この名前はAWS Cognitoで作成されるIdentity Poolリソースを識別するためのものです。
Cognito Identity Poolとは?
- Cognito Identity Poolは、ユーザーに一時的なAWS認証情報を発行する仕組み。
- これにより、ユーザーが直接AWSリソース(例: S3, DynamoDB)にアクセスできるようになります。
- Identity Poolは通常、IAM(Identity and Access Management)と連携して動作します。
Allow unauthenticated logins? (Provides scoped down permissions that you can control via AWS IAM) (Use arrow keys)
Yes
❯ No
I want to learn more.
この選択肢は、Cognito Identity Pool において未認証ユーザー(unauthenticated users)を許可するかどうかを設定するものです。それぞれのオプションについて詳しく説明します。
Allow unauthenticated logins (Yes) を選ぶべき場合:
ゲストユーザーに一部機能を開放したい。
ユーザーがログインせずに利用できる機能がある。
Disallow unauthenticated logins (No) を選ぶべき場合:
アプリ全体を認証済みユーザー限定にしたい。
未認証ユーザーにリソースを公開する必要がない。
Do you want to enable 3rd party authentication providers in your identity pool? (Use arrow keys)
❯ Yes
No
I want to learn more.
この質問は、Cognito Identity Poolにサードパーティ認証プロバイダー(例: Google, Facebook, Amazon, Appleなど)を有効にするかどうかを決めるものです。それぞれの選択肢について詳しく説明します。
Enable 3rd party authentication providers (Yes) を選ぶべき場合:
ソーシャルログイン(例: Google, Facebook)をアプリに統合して、ユーザーエクスペリエンスを向上させたい。
サードパーティ認証がターゲットユーザーにとって便利だと判断できる場合。
Do not enable 3rd party authentication providers (No) を選ぶべき場合:
アプリの認証を独自で管理したい。
サードパーティ認証の提供が不要、または将来的に導入を検討している。
Select the third party identity providers you want to configure for your identity pool: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Facebook
◯ Google
◯ Amazon
◯ Apple
Enable 3rd party authentication providers (Yes)を選択すると表示される項目です。この選択肢は、Cognito Identity Pool で使用するサードパーティ認証プロバイダーを選択するものです。
Provide a name for your user pool: (xxxxxxxxx3e61e0797_userpool_e61e0797)
この質問は、Cognito User Poolの名前を指定する必要があります。指定する名前は、このリソースを識別するためのものです。
Cognito User Poolとは?
Cognito User Poolは、AWSが提供するユーザー認証と管理のためのサービスです。
アプリケーションでのサインアップ、サインイン、パスワードリセットなどの認証機能を提供します。
Warning: you will not be able to edit these selections.
How do you want users to be able to sign in? (Use arrow keys)
❯ Username
Email
Phone Number
Email or Phone Number
I want to learn more.
この選択肢は、ユーザーがどの方法でアプリケーションにサインインするかを設定します。この選択は、Cognito User Poolの構成で重要であり、選択後は変更できないため、慎重に検討する必要があります。
Do you want to add User Pool Groups? (Use arrow keys)
❯ Yes
No
I want to learn more.
この選択肢は、Cognito User Poolにユーザープールグループ(User Pool Groups)を追加するかどうかを決めます。以下に、各選択肢の説明をします。
User Pool Groupsとは?
Cognito User Pool Groupsは、ユーザーをグループに分類するための仕組みです。
グループごとに異なるアクセス権限やロール(IAM Roles)を割り当てることができます。
例えば、「管理者」「編集者」「閲覧者」などの役割をグループで定義し、ユーザーをそれぞれのグループに追加することで簡単に権限管理ができます。
Yes (Add User Pool Groups) を選ぶべき場合:
ユーザーに役割ごとの権限を割り当てたい。
アクセス制御やユーザー管理をAWS Cognitoで完結させたい。
IAMロールを使ってグループごとのリソースアクセス制限を行いたい。
No (Do not add User Pool Groups) を選ぶべき場合:
すべてのユーザーが同じレベルの権限を持つ単純なアプリを構築している。
グループによる制御をアプリケーション側で実装したい。
? Provide a name for your user pool group:
Yes (Add User Pool Groups) を選ぶと表示されます。この質問では、Cognito User Poolに追加するユーザープールグループ(User Pool Group)の名前を指定する必要があります。この名前は、グループを識別するためのものです。
? Do you want to add another User Pool Group (y/N)
この質問では、追加のユーザープールグループ(User Pool Group)を作成するかどうかを確認しています。
? Sort the user pool groups in order of preference … (Use <shift>+<right/left> to change the order)
≡ group1
group2
このステップでは、作成したユーザープールグループ(User Pool Groups)を優先順位順に並べ替える必要があります。
優先順位の意味
Cognito User Poolでは、1人のユーザーが複数のグループに所属できる場合があります。
グループごとに異なるIAMロールが割り当てられている場合、ユーザーに対する権限は最も優先順位の高いグループのIAMロールに基づいて適用されます。
並び順を変更することで、どのグループが優先されるかを設定できます。
Do you want to add an admin queries API? (Use arrow keys)
❯ Yes
No
I want to learn more.
この質問では、AWS AmplifyでAdmin Queries APIを追加するかどうかを設定します。このAPIは、管理者用に特化した操作を提供するためのものです。
Admin Queries APIとは?
- Admin Queries APIは、ユーザー管理に関連する特定の操作を実行するために提供されるAPIです。
- 主に、認証済みの管理者が以下のような操作を実行するために使用します:
- ユーザーの一覧取得
- ユーザーの詳細情報の取得
- ユーザーの削除
- ユーザーのグループへの追加/削除
? Do you want to restrict access to the admin queries API to a specific Group (Y/n)
この質問は、Admin Queries APIのアクセス制御を特定のグループに制限するかどうかを設定します。
? Select the group to restrict access with: (Use arrow keys)
❯ group1
group2
Enter a custom group
この質問では、Admin Queries APIへのアクセスを制限するグループを選択します。
Multifactor authentication (MFA) user login options: (Use arrow keys)
❯ OFF
ON (Required for all logins, can not be enabled later)
OPTIONAL (Individual users can use MFA)
I want to learn more.
この質問は、AWS Cognito User Poolにおける多要素認証(MFA: Multi-Factor Authentication)の設定を選択します。
ONを選んだ場合、最初から全ユーザーでMFAが強制され、後からOFFにしたり、OPTIONAL(ユーザーごとに選択可能)に変更することはできません。
OFFを選んだ場合も後からONに変えることはできません。
MFAとは?
多要素認証(MFA)は、ユーザーのログイン時に追加の認証要素(例: SMSコードや認証アプリのコード)を要求し、セキュリティを強化する仕組みです。
パスワードに加え、ユーザーが所持するデバイス(例: スマートフォン)を利用して認証します。
For user login, select the MFA types: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◉ SMS Text Message
◯ Time-Based One-Time Password (TOTP)
この質問は、AWS Cognito User PoolのMFA(多要素認証)に利用する方法を選択します。
SMS Text Message を選ぶべき場合:
幅広いユーザーに対応したい場合。
ユーザーがシンプルに利用できるMFAを提供したい場合。
TOTP を選ぶべき場合:
セキュリティを優先したい場合。
技術的にリテラシーが高いユーザーを想定している場合。
両方を選ぶべき場合:
ユーザーにMFAタイプの選択肢を提供したい場合。
Specify an SMS authentication message: (Your authentication code is {####})
このステップでは、SMS認証メッセージを設定します。このメッセージは、CognitoがSMSを通じてユーザーに送信するものです。{####} は、Cognitoが生成する認証コードが挿入される場所です。
Email based user registration/forgot password: (Use arrow keys)
❯ Enabled (Requires per-user email entry at registration)
Disabled (Uses SMS/TOTP as an alternative)
この質問は、メールを利用したユーザー登録およびパスワードリセット機能を有効にするかどうかを選択します。それぞれのオプションについて詳しく説明します。
Enabled を選ぶべき場合:
メールアドレスを主要な連絡手段として利用する場合。
パスワードリセットを簡単にしたい場合。
ユーザーがメールを持っていることが前提のアプリケーション(例: Webアプリや一般的なサービス)。
Disabled を選ぶべき場合:
SMSまたはTOTPを中心に運用する場合。
メールを必要としないユースケース(例: モバイルアプリ中心のプラットフォーム)。
Specify an email verification subject: (Your verification code)
Enabledを選ぶと表示されます。メール認証の件名(Subject)は、ユーザーに送信される確認メールの件名部分を指定するものです。この件名は、ユーザーが認証メールをすぐに識別できるようにする重要な要素です。
Specify an email verification message: (Your verification code is {####})
メール認証メッセージは、ユーザーに送信されるメールの本文として利用されます。
Do you want to override the default password policy for this User Pool? (y/N)
この質問では、Cognito User Poolのデフォルトのパスワードポリシーを上書きするかどうかを選択します。それぞれの選択肢について説明します。
デフォルトのパスワードポリシー
- パスワードの長さは 8文字以上。
- 英字(大文字または小文字)と数字が含まれている必要があります。
Enter the minimum password length for this User Pool: (8)
この質問は、Cognito User Poolで使用するパスワードの最小文字数を設定します。
Select the password character requirements for your userpool: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Requires Lowercase
◯ Requires Uppercase
◯ Requires Numbers
◯ Requires Symbols
このステップでは、Cognito User Poolで使用するパスワードの文字要件を設定します。
- Requires Lowercase(小文字が必要)
- Requires Uppercase(大文字が必要)
- Requires Numbers(数字が必要)
- Requires Symbols(記号が必要)
Warning: you will not be able to edit these selections.
What attributes are required for signing up? (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Address (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
◯ Birthdate (This attribute is not supported by Login With Amazon, Sign in with Apple.)
◉ Email
◯ Family Name (This attribute is not supported by Login With Amazon.)
◯ Middle Name (This attribute is not supported by Google, Login With Amazon, Sign in with Apple.)
◯ Gender (This attribute is not supported by Login With Amazon, Sign in with Apple.)
◯ Locale (This attribute is not supported by Facebook, Google, Sign in with Apple.)
◯ Given Name (This attribute is not supported by Login With Amazon.)
◯ Name
◯ Nickname (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
◯ Phone Number (This attribute is not supported by Facebook, Login With Amazon, Sign in with Apple.)
◯ Preferred Username (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
◯ Picture (This attribute is not supported by Login With Amazon, Sign in with Apple.)
◯ Profile (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
◯ Updated At (This attribute is not supported by Google, Login With Amazon, Sign in with Apple.)
◯ Website (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
◯ Zone Info (This attribute is not supported by Facebook, Google, Login With Amazon, Sign in with Apple.)
この質問は、ユーザー登録時に必須となる属性を選択します。選択した属性は、ユーザーがサインアップ時に必ず入力する必要があり、それがCognito User Poolのユーザープロファイルに保存されます。
Specify the app's refresh token expiration period (in days): (30)
この設定では、リフレッシュトークンの有効期限を指定します。この期限は、アプリケーションでユーザーがログイン状態を維持する期間に影響します。
Do you want to specify the user attributes this app can read and write? (y/N)
この質問では、アプリケーションがCognito User Poolのユーザー属性を読み書きできる権限を設定するかどうかを選択します。
Specify read attributes: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Address
◯ Birthdate
◉ Email
◯ Family Name
◯ Middle Name
◯ Gender
◯ Locale
◯ Locale
◯ Given Name
◯ Name
◯ Nickname
◯ Phone Number
◯ Preferred Username
◯ Picture
◯ Profile
◯ Updated At
◯ Website
◯ Zone Info
◯ Email Verified?
◯ Phone Number Verified?
この設定は、アプリケーションが読み取ることを許可されるユーザー属性を選択します。
Specify write attributes: (Press <space> to select, <a> to toggle all, <i> to invert selection)
--- You have already selected the following attributes as required for this User Pool. They are writeable by default: Email ---
❯◯ Address
◯ Birthdate
◯ Family Name
◯ Middle Name
◯ Gender
◯ Locale
◯ Locale
◯ Given Name
◯ Name
◯ Nickname
◯ Phone Number
◯ Preferred Username
◯ Picture
◯ Profile
◯ Updated At
◯ Website
◯ Zone Info
この設定では、アプリケーションがユーザー属性を更新できる(書き込み可能)かどうかを選択します。この例の場合はメールアドレスはユーザ・プールに必要な属性なのでデフォルトで書き込み可能になっています。
Do you want to enable any of the following capabilities? (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Add Google reCaptcha Challenge
◯ Email Verification Link with Redirect
◯ Add User to Group
◯ Email Domain Filtering (denylist)
◯ Email Domain Filtering (allowlist)
◯ Custom Auth Challenge Flow (basic scaffolding - not for production)
◯ Override ID Token Claims
この設定では、AWS Amplify Cognito User Poolにおける追加の機能やカスタマイズを有効にするかを選択します。
- Add Google reCaptcha Challenge: ユーザー登録またはログイン時にGoogleのreCaptchaを追加し、ボットからのアクセスを防ぎます。
- Email Verification Link with Redirect: ユーザーのメールアドレス認証時に、リンクをクリックした後にリダイレクトするURLを指定できます。
- Add User to Group: ユーザーを特定のグループに追加する機能を提供。(例: ユーザー登録後に「StandardUser」グループに自動的に追加)
- Email Domain Filtering (denylist): 特定のメールドメイン(例: gmail.com)の登録を禁止。
- Email Domain Filtering (allowlist): 特定のメールドメイン(例: gmail.com)だけを許可。
- Custom Auth Challenge Flow (basic scaffolding - not for production): カスタム認証チャレンジフローの基本的なセットアップを提供。(例: 追加のセキュリティステップを挿入(独自の質問/回答))
- Override ID Token Claims: IDトークンに含まれるクレームを上書きできます。
ID トークンのクレームとは?
ID トークンは、OAuth 2.0 と OpenID Connect (OIDC) のプロトコルで使用される JSON Web Token (JWT) の一種です。このトークンには、認証されたユーザーに関する情報(クレーム)が含まれています。
Do you want to use an OAuth flow? (Use arrow keys)
❯ Yes
No
I want to learn more.
この質問は、OAuthフローをアプリケーションに使用するかどうかを設定します。
What domain name prefix do you want to use? (xxxxxxxxx3ef1e8eed-ef1e8eed)
この質問では、Cognito Hosted UIのカスタムドメイン名のプレフィックスを指定します。このプレフィックスは、アプリケーションの認証URLの一部となり、ユーザーがログインやサインアップにアクセスする際に使用されます。
AWS Cognito User Pool で提供されるホストされた UI(サインイン、サインアップ、パスワードリセットなど)や、OAuth 2.0 のエンドポイントの URL を生成するために必要です。
Enter your redirect signin URI:
Redirect Sign-in URIは、ユーザーがログイン認証後にリダイレクトされるURLを指定します。この設定は、アプリケーションとCognitoが統合される際に重要です。
? Do you want to add another redirect signin URI (y/N)
この質問は、追加のリダイレクトサインインURIを設定するかどうかを選択します。
Enter your redirect signout URI:
Redirect Sign-out URIは、ユーザーがログアウト操作を行った後にリダイレクトされるURLを指定します。
? Do you want to add another redirect signout URI (y/N)
この質問は、追加のRedirect Sign-out URIを設定する必要があるかどうかを確認しています。
Select the OAuth flows enabled for this project. (Use arrow keys)
❯ Authorization code grant
Implicit grant
この質問は、アプリケーションで使用するOAuthフローを選択します。
- Authorization Code Grant: より安全なOAuthフローで、認可コードを使用してアクセストークンを取得します。
- フロー
- ユーザーがCognitoの認証画面でログイン。
- 認可コードが指定のリダイレクトURIに返される。
- アプリケーション(サーバーサイド)が認可コードを使ってアクセストークンを取得。
- フロー
- Implicit Grant: クライアント(ブラウザやフロントエンド)にアクセストークンを直接返す簡易的なOAuthフロー。
- フロー
- ユーザーがCognitoの認証画面でログイン。
- トークンが指定のリダイレクトURIに返される。
- フロー
Select the OAuth scopes enabled for this project. (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◉ Phone
◉ Email
◉ OpenID
◉ Profile
◉ aws.cognito.signin.user.admin
この質問では、アプリケーションで使用するOAuthスコープを選択します。スコープは、アプリケーションがどのユーザー情報や機能にアクセスできるかを制御します。
Select the social providers you want to configure for your user pool: (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Facebook
◯ Google
◯ Login With Amazon
◯ Sign in with Apple
この質問では、AWS Cognito User Poolで使用するソーシャル認証プロバイダーを選択します。
? Do you want to configure Lambda Triggers for Cognito? (Y/n)
この質問では、Cognito Lambda Triggersを設定するかどうかを選択します。Lambda Triggersを使用すると、AWS Lambda関数を介してCognitoの認証フローやユーザー操作をカスタマイズできます。
? Which triggers do you want to enable for Cognito (Press <space> to select, <a> to toggle all, <i> to invert selection)
❯◯ Learn More
──────────────
◯ Create Auth Challenge
◯ Custom Message
◯ Define Auth Challenge
◯ Post Authentication
◯ Post Confirmation
◯ Pre Authentication
◯ Pre Sign-up
◯ Verify Auth Challenge Response
◯ Pre Token Generation
(Move up and down to reveal more choices)
このステップでは、Cognito Lambda Triggersの中からどのトリガーを有効にするかを選択します。
- Create Auth Challenge: ユーザー認証時にカスタムチャレンジを作成するために使用。
- Custom Message: メールやSMSのメッセージをカスタマイズする。
- Define Auth Challenge: 認証フロー内で次のステップを定義する。
- Post Authentication: ユーザーが認証成功後にカスタムロジックを実行。
- Post Confirmation: ユーザーがサインアップ後にアカウントを確認した直後に実行。
- Pre Authentication: ユーザーがログインする前にカスタムロジックを実行。
- Pre Sign-up: ユーザーがサインアップする直前にカスタムロジックを実行。
- Verify Auth Challenge Response: ユーザーがチャレンジに応答した後に応答の検証を行う。
- Pre Token Generation: アクセストークンやIDトークンの生成前にカスタムロジックを実行。
これで設定ファイルが作成されます。色々と細かい設定ができる印象ですね。
最後にamplify pushをすることを忘れないように!
Discussion