pycognito icon indicating copy to clipboard operation
pycognito copied to clipboard

After authentication, I want to return the token to frontend people.

Open aalokrmb opened this issue 4 years ago • 2 comments

After authentication, I want to return the token to the front-end team, but as I can see you are not returning anything from the authentication, so whatever line of code I wrote after the authenticate line, never runs. Example:

u = Cognito('your-user-pool-id','your-client-id', username='bob')
u.authenticate(password='bobs-password')
print("@"*50)

In this line of code, the print statement never executes, because we didn't get any response from the authenticate method.

aalokrmb avatar Oct 18 '21 06:10 aalokrmb

In the code you provide, print would run if authenticate returned successfully. But inside of that method is this try block:

try:
    tokens = aws.authenticate_user(client_metadata=client_metadata)
except MFAChallengeException as mfa_challenge:
    self.mfa_tokens = mfa_challenge.get_tokens()
    raise mfa_challenge
else:
    self._set_tokens(tokens)

So it seems like what is actually happening is that an MFAChallengeException is being raised. Can you catch the exception and handle it?

nk9 avatar Nov 12 '22 22:11 nk9

ParseAccessTokenu = dict(jwt.get_unverified_claims(u.access_token))
tokendict = {'AccessToken':u.access_token,
             'ExpiresIn': ParseAccessTokenu.get("exp")-ParseAccessTokenu.get("auth_time"),
             'Expires_Datetime': str(datetime.fromtimestamp(ParseAccessTokenu.get("exp"))),
             'TokenType': u.token_type,
             'RefreshToken': u.refresh_token,
             'IdToken': u.id_token}

now you have a dict anche you can use ;-)

avanguardigit avatar Jan 26 '23 15:01 avanguardigit