LoginSignup
5
7

More than 3 years have passed since last update.

AWS Amplify フレームワークの使い方Part13〜Auth 設定更新編〜

Posted at

はじめに

あとあとAuthの設定を変更したいということは出てくるかと思います。変更不可な項目もありますが、今回はAmplifyを通して更新できるものを紹介していきます。

バージョン

amplify-cli 4.32.1

Authの設定

まずはおなじみのコマンドから実行で複数の選択項目が出てきます。Authの設定状況によってこの項目は変わるようなので、知っている範囲内で解説していきます。

$ amplify auth update
 What do you want to do? (Use arrow keys)
  Apply default configuration without Social Provider (Federation) 
  Apply default configuration with Social Provider (Federation) 
❯ Walkthrough all the auth configurations 
  Add/Edit signin and signout redirect URIs 
  Update OAuth social providers 
  Create or update Cognito user pool groups 
  Create or update Admin queries API 

Apply default configuration without Social Provider (Federation)

ソーシャルプロバイダなしでのCognitoのデフォルトをテンプレートに作り直してくれます。

Apply default configuration with Social Provider (Federation)

ソーシャルプロバイダありでのCognitoのデフォルトをテンプレートに作り直してくれます。

Add/Edit signin and signout redirect URIs

ソーシャルログインでのサインインおよびサインアウト時の遷移先のURLを更新できます。

Update OAuth social providers

OAuthの設定を更新できます。

Create or update Cognito user pool groups

Cognitoのグループの新規作成および更新が行なえます。

Create or update Admin queries API

いまだによくわかっていない、このアドミン用API。管理者グループに所属していればなんでもアクセス化的なことなんだとは思っているのですが、手つかずでございます。

Walkthrough all the auth configurations

細かい設定を行う場合はこの項目を選択して各項目の再設定をしていきます。

更新ができる全項目についてどうするか聞かれますので、1つ1つ設定をしていきます。

User Sign-Up, Sign-In, connected with AWS IAM controls (Enables per-user Storage fe

atures for images or other content, Analytics, and more)
選択項目はこの1つのみなので、そのまま選択。

Do you want to add User Pool Groups? (Use arrow keys)

Cognitoのグループの変更(削除、追加、優先順位変更)がこの項目から行えます。

Do you want to add an admin queries API? (Use arrow keys)

いまだによくわかっていない、このアドミン用API。管理者グループに所属していればなんでもアクセス化的なことなんだとは思っているのですが、手つかずでございます。とりあえず、Noを選択。

Email based user registration/forgot password: (Use arrow keys)

新規登録時およびパスワード忘れたときの認証をメールで行うか、
基本メールでいいと思っています。(SMS/TOTPの場合をあまり白台だけ。)

❯ Enabled (Requires per-user email entry at registration) 
  Disabled (Uses SMS/TOTP as an alternative) 

Please specify an email verification subject:

メール認証を有効にした場合の件名の入力。

Please specify an email verification message:

メール認証を有効にした場合の文章入力。

Do you want to override the default password policy for this User Pool?

パスワードポリシーを変更したい場合はこちらから。

Specify the app's refresh token expiration period (in days):

リフレッシュトークンの有効期限の変更。

Do you want to specify the user attributes this app can read and write? (y/N)

ユーザー属性(usernameとかemail)の読み込みと書き込み権限の再設定ができます。

Do you want to enable any of the following capabilities?

便利な機能たちがこんなにも簡単に実装できるなんて素晴らしい。(まだどれも試したことはないが。)

 ◯ Add Google reCaptcha Challenge
 ◯ Email Verification Link with Redirect
 ◯ Add User to Group
 ◯ Email Domain Filtering (blacklist)
❯◯ Email Domain Filtering (whitelist)
 ◯ Custom Auth Challenge Flow (basic scaffolding - not for production)
 ◯ Override ID Token Claims

Do you want to use an OAuth flow? (Use arrow keys)

OAuthの再設定ができます。Googleやfacebookのログイン設定をしたい場合はこちらから。

? Do you want to configure Lambda Triggers for Cognito? (Y/n)

Cognitoのトリガーに紐づく、Lambda関数を作成できます。

注意点として、そのLambda関数に色んなリソースのアクセス権限をつけてPUSHをするとエラーが起き更新ができなくなってしまうバグがあるため、注意が必要です。

現時点で、解決方法が見つからなかったので、普通に関数を作ってGUIからトリガーしているのが現状です。GUI管理は極力なくしたいので、いずれは解決したい問題の1つ。

Circular dependency between resources: [他の関数リソース名]
An error occurred during the push operation: Circular dependency between resources: [他の関数リソース名]

注意点/わかったこと

選択方法によって、上書きのされ方が違う

「Walkthrough all the auth configurations 」で設定をする場合は、問に対してNoと答えた場合は、
あくまでも設定しない、の意味なので、上書き処理は走らずに、前回の設定がそのまま残りました。

逆に「Update OAuth social providers」でOAuthの設定をしたときは、完全に OAuth情報が上書きされるため、1つOAuthのプロバイダを追加した場合は、必ず以前のプロバイダ情報も一緒に入力する必要があります。

項目ごとに検証はできていませんが、注意が必要です。

自分で追加したCloudFomationは要注意

$amplify auth updateで更新を行うと、amplifyフォルダ内のauthのファイルが更新されます。その際に、これまでにxxxxxxx -cloudformation-template.ymlのファイルに手書きで追加したコードについては消えてしまいます。
それに気づかずにpushしてしまうとエラーになって悲しいことになってしまいますので、更新後には必ずxxxxxxx -cloudformation-template.ymlに手書きコードを追加してからpushしましょう。

環境間で引き継がない情報もある

基本的には、環境を移動(amplify env checkout)したあとに、pushすれば、別の環境で整えた環境がそのまま同じように出来上がります。
細かく検証ができていませんが、例えばOAuthの登録した情報は基本的には引き継がれず、その環境ごとに設定が必要なようです。(OAuthに関して言えば、当たり前といえば当たり前だが。)

OAuthの設定については、もっとうまくやれる気はしているが、なにかシンプルな方法があれば教えてほしい、、、。

おわりに

Cognito自体はまだ使い切れていない機能がたくさんありそうなので、引き続き精進しなければと感じております。
Amplifyを利用する人の一助になれば幸いです。よきAmplifyライフを!!

関連記事

AWS amplify フレームワークの使い方Part1〜Auth設定編〜
AWS Amplify フレームワークの使い方Part2〜Auth実践編〜
AWS Amplify フレームワークの使い方Part3〜API設定編〜
AWS Amplify フレームワークの使い方Part4〜API実践編〜
AWS Amplify フレームワークの使い方Part5〜GraphQL Transform @model編〜
AWS Amplify フレームワークの使い方Part6〜GraphQL Transform @auth編〜
AWS Amplify フレームワークの使い方Part7〜GraphQL Transform @key編〜
AWS Amplify フレームワークの使い方Part8〜GraphQL Transform @connection編〜
AWS Amplify フレームワークの使い方Part9〜Function 基礎編〜
AWS Amplify フレームワークの使い方Part10〜Storage編〜
AWS Amplify フレームワークの使い方Part11〜Function 権限管理編〜
AWS Amplify フレームワークの使い方Part12〜ENV編〜

5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7