Looks like you answered your question already. Any API call with an expired
access token will drop an error by the provider, 401 in the case of google, so
it's easy to identify in that way. You can use the expires_in to check it, but
there's no date to get as reference in the application, but you can add
a pipeline to function that will add that to details and then tell the
application to store it in extra data, something like this:
import time
def set_current_date(details, *args, **kwargs):
details['updated_at'] = int(time.time())
And the setting:
SOCIAL_AUTH_GOOGLE_OAUTH2_EXTRA_DATA = ['updated_at']
I'll happy to merge a PR with this added to the docs.
Matías
Excerpts from Greg Barker's message of 2014-05-06 20:06:28 -0300:
> Whoops forgot a line in my example:
>
> strategy = load_strategy('google-oauth2')
>
> As far as when to refresh the token, I think I've found the answer. The
> Google API responds with a 401 after the access_token expires, and then you
> do the refresh_token. My expires_in was 3600, so I guess that means seconds
> since my last post was an hour ago (and the google docs<
https://developers.google.com/accounts/docs/OAuth2WebServer#offline>don't indicate units).
>
> Perhaps we could get this example added to the Google backend docs similar
> to the reddit backend docs?
>
> On Tuesday, May 6, 2014 2:39:34 PM UTC-7, Greg Barker wrote:
> >
> > I added the following to my settings.py:
> >
> > SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = {'access_type': 'offline'}
> >
> > Now my UserSocialAuth.extra_data has an additional key, refresh_token. I
> > was able to refresh the token using code similar to the reddit example<
http://www.google.com/url?q=http%3A%2F%2Fpsa.matiasaguirre.net%2Fdocs%2Fbackends%2Freddit.html&sa=D&sntz=1&usg=AFQjCNH60DwWzPAo3dfwDPyumLoCM-kcdA>
> > :
--
Matías Aguirre (
matias...@gmail.com)