Вопрос

I am developing an app on Google AppEngine, and utilizing Google+ SignIn with server-side flow method as documented here.
I can get the token as above, and stores it in session.
However, i want to check at login, if the token is valid or has expired. How can i do that?
Note: I use Google API client libs for java.

Это было полезно?

Решение

You can call the tokeninfo API method to get info about a token, including how long before it expires (if < 0, token is expired)

https://developers.google.com/resources/api-libraries/documentation/oauth2/v2/java/latest/com/google/api/services/oauth2/model/Tokeninfo.html

Другие советы

In addition to Jason's answer:

You could also estimate if the token is still good by setting another session cookie with the timestamp of when you acquired the token. They expire approximately hourly (there is some variability).

Since the tokeninfo endpoint requires a request, you could also skip hitting the tokeninfo endpoint unless you have other reasons, such as needing to verify that the token matches the app and user, and just make normal requests until they you get a bad request error. When you get that attempt to refresh your token.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top