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

Restore AccessToken #431

Closed
EugeneVdovenko opened this issue Sep 10, 2015 · 10 comments
Closed

Restore AccessToken #431

EugeneVdovenko opened this issue Sep 10, 2015 · 10 comments

Comments

@EugeneVdovenko
Copy link

I am store the data from AccessToken in $_SESSION.

When I want restoring AccessToken from $_SESSION

$accessToken = new AccessToken($_SESSION['accessToken']);

I can have wrong expires-field, and method hasExpires() returns «true» always.

For example, if user use access_token after expired time, constructor writes to expires-filed

time()+«time_from_SESSION»

I mean it's wrong

@shadowhand
Copy link
Member

After looking at the code, I can make some sense of this. Basically, the issue is when you construct AccessToken from stored values, instead of completely fresh values, it will use the existing expiration time as a second value instead of as a timestamp.

I'm not really sure what to do about this. Pushing the normalization of the expires (in) outside probably makes the most sense.

@ramsey
Copy link
Contributor

ramsey commented Sep 11, 2015

Our AccessToken class uses a Unix timestamp for expires, so it should always evaluate correctly. Is the problem that end-users are storing "expires_in" in the database/session and restoring from that causes problems?

@shadowhand
Copy link
Member

@ramsey the problem is when the token expires in the past it is assumed to be "the same as" expires_in. We could probably do something sane like:

// October 2012, the initial release of OAuth 2.0
if ($expires < 1349067600) { ... }

... rather than the blind "in the past" check we are doing now. I doubt anyone is issuing tokens that expire in 3+ years.

@rtheunissen
Copy link
Contributor

Hah this is such an interesting case. I can't think of a nicer way than what @shadowhand has suggested. Unless we can somehow specify on a per-provider basis whether its token should use "expires in" or "expires at".

Or as an option when constructing the token? Specifies as either TOKEN_EXPIRES_IN, TOKEN_EXPIRES_AT or TOKEN_EXPIRES_AUTO.

@stevenmaguire
Copy link
Member

This is an interesting case indeed. When I was writing test cases to bring the package to 100% coverage, it felt odd the way the Token handles the expiration. I'd like the package to remain simple with limited complexity so I like the solution proposed by @shadowhand. I do also like the package to be receptive to consumer intent and the "modes" @rtheunissen proposed would offer a bit of that; the package could still carry a default preference.

@TrafeX
Copy link

TrafeX commented Sep 22, 2015

What can we do to solve this? I'm also running into this issue which basically means you can't construct an AccessToken with an expired expiration date.
The only workaround it I could think of was using the expires_in and subtracting the time() value of what we have in our datastore.

@shadowhand
Copy link
Member

@TrafeX @ramsey PR created.

@shadowhand
Copy link
Member

@TrafeX This will go out in v1.0.2.

@ramsey
Copy link
Contributor

ramsey commented Sep 22, 2015

And v1.0.2 is now out!

@TrafeX
Copy link

TrafeX commented Sep 23, 2015

@shadowhand @ramsey That was fast, thanks guys!

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

6 participants