pmill / aws-cognito

A PHP library for AWS Cognito user pools
MIT License
74 stars 62 forks source link

What to do after access_token expire and there is no refresh token? #11

Closed pedjaman closed 5 years ago

pedjaman commented 6 years ago

I was using builtin login page. When using response_type=token i don't get refresh token. When using response_type=code I don't see a way to utilize this class.

So with first approach, after some time, following exception is trigerred (marked with "HERE"):

           try
            {
                $this->client->verifyAccessToken($access_token);
            }
            catch(\pmill\AwsCognito\Exception\TokenExpiryException $e)
            {
// HERE
            }

What would be the best approach to handle this case?

Thank you for this class :)

claytonpiccinin commented 6 years ago

You can call refreshAuthentication class passing $username and $access_token, it shoult renew and return a new token to be stored.

pedjaman commented 6 years ago

Thank you for your response. Unfortunately, that doesn't help. It is throwing an exception.

pmill commented 6 years ago

Hi there, do you know what exception is being throw when you call refreshAuthentication()?

pedjaman commented 6 years ago

Hi :) unfortunately I cannot recall. Not curently actiove on the project. But it does require refresh_token instead of access_token

pmill commented 6 years ago

So the call to authenticate() returns an AuthenticationResultType object, you should be able to grab the refresh token from that.

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AuthenticationResultType.html

pedjaman commented 6 years ago

As far as I know from my tests and looking to documentation, there is not refresh_token returned if response_type=token based approach is used. I had to switch using response_type=code based then getting tokens based on code. But if i get a chance, I will try this above.