AWS Cognito를 Python에서 처리
AWS Cognito를 Python에서 호출하려고하면 성대하게 빠졌습니다.
사전 준비
Cognito에 대한 액세스를 허용하는 IAM을 생성합니다.
AWS Cognito에서 UserPool 생성






파이썬 설정
버전
사용자 작성
import boto3
def cognito_auth(username, email, gender, birthday, nickname):
# 認証開始
try:
aws_client = boto3.client('cognito-idp',
region_name = 'ap-northeast-1',
aws_access_key_id = '***',
aws_secret_access_key = '***',
)
# ユーザー作成
aws_result = aws_client.admin_create_user(
# cognito設定時のユーザープールID
UserPoolId='***',
Username=username,
UserAttributes=[
{
'Name': 'email',
'Value': email
},
{
'Name': 'gender',
'Value': gender
},
{
'Name': 'birthdate',
'Value': birthdate
},
{
'Name': 'nickname',
'Value': nickname
},
],
# Mailに初期パスワードを送信する
DesiredDeliveryMediums=['EMAIL']
)
# 認証完了
print(aws_result)
except:
# 認証失敗
print('Error')
cognito_auth('username', 'email', 'gender', 'birthdate', 'nickname')
승인 요청
response = aws_client.initiate_auth(
# PASSWORDによる承認
AuthFlow='USER_PASSWORD_AUTH',
AuthParameters={
'USERNAME': '***',
'PASSWORD': '***'
},
ClientId='***'
)
print(response)
승인 요청에 대한 답변
response = aws_client.respond_to_auth_challenge(
ClientId='***',
ChallengeName='ChallengeName',
Session='***',
ChallengeResponses={
'NEW_PASSWORD': 'NEW_PASSWORD',
'USERNAME': 'USERNAME'
}
)
print(response)
추가 (2019/1/26)
Cognito의 update_at 유형
update_at에 값을 넣을 때 형식 변환하지 않으면 boto3에서 오류가 반환됩니다.
최종 선언 방법은 다음과
str(int(time.time()))
미래
새로운 API를 사용할 때는 추가한다.
Reference
이 문제에 관하여(AWS Cognito를 Python에서 처리), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/yakult/items/2cbb2f57c97487b6268b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)