4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

API GatewayのCognito UserPools AuthorizerでCognitoのcustom attributesを取得する

Posted at

API GatewayでCognitoのカスタム属性(custom attributes)を使用したくなる場合があります。

スクリーンショット 2018-03-17 19.53.21.png ⬆ここにカスタム属性を含められればそのままLambdaへ渡せるので便利。

Cognito UserPools Authorizerを使用する方法自体は以下が参考になります。

今回はここにCognitoのカスタム属性を含める方法を記載します。

手順

カスタム属性を作成する

  • Cognito > ユーザープール > 属性 > カスタム属性の追加

カスタム属性に値を格納

AWS CLI を使用してcustom:my-address というカスタム属性に値を格納する例。

aws cognito-idp admin-update-user-attributes \
  --user-pool-id ap-northeast-1_XXXXXXXX \
  --username foobar \
  --user-attributes "[{\"Name\":\"custom:my-address\",\"Value\":\"0x9A84E702e8D82Ac4522d4E0790C141696d89d324\"}]" \

アプリクライアントの属性への読み取り権限を付与する

  • Cognito > アプリクライアント > 詳細を表示 > 属性の読み込みおよび書き込みアクセス権限を設定する
スクリーンショット 2018-03-17 19.38.32.png

対象のクライアントでアクセストークンを生成

  • 詳細割愛

オーサライザーで確認

スクリーンショット 2018-03-17 19.52.52.png
  • :warning: トークンは取得し直さなければ反映されない場合あり

以上。

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?