Boto3 for social logins using Cognito UserPools

I have a mobile application with signup / signin options. The Mobile application calls the Restore APIs, and the APIs use the Python boto3 CognitoIdentityProvider client to create users in AWS Cognito user pools. SignIn using email / password works fine.

For social login, the mobile application is updated by using google login and retrieving idToken, accessToken. How to use google returned signIn token to login / create user to Cognito user pool from python backend environment? Is it possible?

For the username and password parameters, I use signup and admin_initiate_auth . But not sure what to use so that users can sign up or create users in UserPool using the google / facebook signin parameter.

Essentially, there is a way in Boto3 or other AWS libraries for creating users in UserPool using google / facebook returned by idToken>

+5
source share
1 answer

get_id method from boto3 CongnitoIdentity service addresses the problem.

Using the token returned by google, call get_id to create a federated identifier.

client = boto3.client('cognito-identity', aws_access_key_id=ACCESS_KEY, aws_secret_access_key=ACCESS_SECRET_KEY) response = client.get_id( AccountId='YOUR AWS ACCOUNT ID', IdentityPoolId='us-east-1:xxxdexxx-xxdx-xxxx-ac13-xxxxf645dxxx', Logins={ 'accounts.google.com': 'google returned IdToken' }, ) 

The answer includes a Cognito IdentityId:

 { "ResponseMetadata": { "RetryAttempts": 0, "HTTPStatusCode": 200, "RequestId": "xxxfb049b-1f77-xxxx-a67c-xxxfb049b", "HTTPHeaders": { "date": "Sun, 04 Mar 2018 06:43:13 GMT", "x-amzn-requestid": "xxxfb049b-1f77-xxx-a67c-xxxfb049b", "content-length": "63", "content-type": "application/x-amz-json-1.1", "connection": "keep-alive" } }, "IdentityId": "us-east-1:xxx-2xx1-1234-9xx2-xxxx" } 
+4
source

Source: https://habr.com/ru/post/1275573/


All Articles