Ejemplo n.º 1
0
#!/usr/bin/env python3
from common.config import config
from common.colourprint import Printer
from warrant import Cognito

props = config()

cognito = Cognito(props['USER_POOL_ID'],
                  props['CLIENT_ID'],
                  user_pool_region='eu-west-1',
                  username=props['USERNAME'])

print('Requesting a password reset for {}'.format(props['USERNAME']))
cognito.initiate_forgot_password()

Printer.success()
client = boto3.client('cognito-idp')
identity_client = boto3.client('cognito-identity')
sync_client = boto3.client('cognito-sync', aws_access_key_id=props['AWS_ACCESS_KEY_ID'], aws_secret_access_key=props['AWS_SECRET_ACCESS_KEY'])

response = client.admin_initiate_auth(
    UserPoolId=props['USER_POOL_ID'],
    ClientId=props['ADMIN_CLIENT_ID'],
    AuthFlow='CUSTOM_AUTH',
    AuthParameters={
        'USERNAME': props['USERNAME']
    }
)

if 'ChallengeName' in response:
    Printer.err("Challenge needs to be completed (Not Implemented)")

if 'AuthenticationResult' in response:
    identity_response = identity_client.get_id(
        AccountId=props['IDENTITY_POOL_ACCOUNT_ID'],
        IdentityPoolId=props['IDENTITY_POOL_ID'],
        Logins={ 'cognito-idp.eu-west-1.amazonaws.com/{}'.format(props['USER_POOL_ID']): response['AuthenticationResult']['IdToken'] })

    identity_id = identity_response['IdentityId']
    print('Identity ID = {}'.format(identity_id))
    print('')
    print('Listing Records')

    # Uncomment below if you want to manage datasets as a Cognito user, rather than an admin
    # credentials_response = identity_client.get_credentials_for_identity(
    #     IdentityId=identity_id,