After authentication, I want to return the token to frontend people.
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.
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?
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 ;-)