Yes, each time you invoke stackexchange.com/oauth/
, you will get a fresh access token, even though old ones may still be valid.
For example:
- Go to
/me/inbox
Livedoc and hit Get Token twice, recording the token value each time (It will always be different). - Then go to
/access-tokens/{accessTokens}
Livedoc and check each token. They will both still be valid! (Valid tokens return an entry in theitems
array. Invalid or expired tokens return nothing.)
At the very least, one would expect that issuing a new token for the same app+permissions+user should invalidate old tokens for that app+permissions+user. Littering the bitbucket with lots of unused, but valid, tokens just makes it easier for bad guys. ;)
Returning the last-issued token, if it is still valid, would be convenient, but there maymight be some reason not to.
You can submit a feature-request to changeimprove these behaviors but, unless a definite vulnerability is shown, it may be a while before anything changes. (API development seems to have stalled.)
Workaround-ish:
If you know who the user is by some other means (cookie, localStorage
, etc.), and you stored her last valid access_token
, you can use /access-tokens/{accessTokens}
to see if that token is still valid.
If it is, just use that token and skip the fresh call to stackexchange.com/oauth/
.
You need a way to track a user outside of access_token
, but you should be doing that anyway.
Tokens are meant to be ephemeral and identification and authorization should be kept separate.
Also, protect yourself and the user and /access-tokens/{accessTokens}/invalidate
tokens when you are done with them or if you are calling stackexchange.com/oauth/
for a fresh token.