Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expires_in, expires_datetime attributes missing from Cognito instance after authenticate() #16

Open
kairstenfay opened this issue Aug 4, 2020 · 3 comments

Comments

@kairstenfay
Copy link

Hi, I am using pycognito following your authenticate example from the README.

When I run the authenticate() method on a Cognito instance (created with a Cognito User Pool ID, Cognito Client ID, and username), I do not get an instance with the .expires_in or .expires_datetime attributes as described. I do see id_token, refresh_token, access_token, and token_type, though.

@kairstenfay kairstenfay changed the title expires_in, expires_datetime attributes missing from cognito object expires_in, expires_datetime attributes missing from Cognito instance after authenticate() Aug 4, 2020
@jusexton
Copy link

jusexton commented Aug 21, 2020

Taking a quick look at the authentication function, it does not set the expires_in nor expires_datetime attributes. The expires_in field is however within the tokens response coming from the .authenticate_user() function, just need to make use of it. Looks like an easy fix.

.authenticate_user() acquires the tokens by calling respond_to_auth_challenge() from boto3.

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.respond_to_auth_challenge

def authenticate(self, password):
    """
    Authenticate the user using the SRP protocol
    :param password: The user's passsword
    :return:
    """
    aws = AWSSRP(
        username=self.username,
        password=password,
        pool_id=self.user_pool_id,
        client_id=self.client_id,
        client=self.client,
        client_secret=self.client_secret,
    )
    tokens = aws.authenticate_user()
    self.verify_token(tokens["AuthenticationResult"]["IdToken"], "id_token", "id")
    self.refresh_token = tokens["AuthenticationResult"]["RefreshToken"]
    self.verify_token(
        tokens["AuthenticationResult"]["AccessToken"], "access_token", "access"
    )
    self.token_type = tokens["AuthenticationResult"]["TokenType"]
    # Set expires_in and expires_datetime with tokens["AuthenticationResult"]["ExpiresIn"]

On a side note, many other functions would need to be updated to assign these attributes, not just the authenticate() function.

@janhurst
Copy link

janhurst commented Dec 2, 2020

Seeing the same behaviour... is the README just not quite aligned with what actually happens? Is there a different flow where those attributes are being set?

@jusexton
Copy link

jusexton commented Dec 3, 2020

@janhurst Seems like the README is not aligned with what is actually happening. There is not another flow that I am aware of. Nothing seems to be making use of the ExpiresIn field coming back from boto3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants