LoginSignup
0
0

More than 3 years have passed since last update.

LambdaからAuthFlow=USER_SRP_AUTHでCognitoの認証を通す

Last updated at Posted at 2020-07-14

目的

LambdaからInitiateAuthAuthFlowUSER_SRP_AUTHでCognitoの認証を通す。

AdminInitiateAuthADMIN_USER_PASSWORD_AUTHを使って良いならそっち推奨
(boto3のadmin_initiate_auth使ってID/PWだけで簡単に実装できる。)

方法

自力でやろうとすると、initiate_authrespond_to_auth_challengeを実行する必要があるが、
respond_to_auth_challengeの方のPASSWORD_CLAIM_SIGNATUREの計算で挫折してしまうため、
こちらを拝借する。。
pip installできる(はず)だが、ファイル数が少ないので直接ダウンロードして使う。

__init__.pyが居ると、色々インストールしないといけなくなるため、削除してしまってOK。
(↓になるように)
image.png

Lambdaに下記を実装する。

from warrant.aws_srp import AWSSRP

u = AWSSRP(pool_id='ユーザプールID', client_id='クライアントID', username='ID', password='PW')
res = u.authenticate_user()
id_token = res['AuthenticationResult']['IdToken']

スペシャルサンクス

0
0
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
0
0