Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

How can I guess AccesToken object with a token String #45

Open
luisruelas opened this issue May 19, 2020 · 1 comment
Open

How can I guess AccesToken object with a token String #45

luisruelas opened this issue May 19, 2020 · 1 comment

Comments

@luisruelas
Copy link

Hello, I want to know if my token has expired, I update my database with all the token information (auth code, token, refresh_token, expires) and I would like to call $token->hasExpired(), but I do not know how to get an AccessToken object ($token) to call the function. I have tried $this->provider->getAccessToken('access_token', ['access_token'=>$string]) but I tried it more out of desperation than anything.

@djchen
Copy link
Owner

djchen commented May 19, 2020

I would recommend directly checking that expires value from the database against the current time to see if its expired.

It's not possible to reconstruct the AccessToken object with simply the token string.
However if you have all of the necessary fields from AccessToken stored in your database, you can use its constructor to create a new instance with those values:
https://github.com/thephpleague/oauth2-client/blob/master/src/Token/AccessToken.php#L59
You'll need to pass in that $options array with access_token, refresh_token, expires_in, etc.

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

No branches or pull requests

2 participants