问题描述:

I have the following working right after a user uses omniauth-google-oauth2:

auth = User.first.authentications.first

client = OAuth2::Client.new('removed', 'removed', :site => 'https://accounts.google.com')

oauth2_object = OAuth2::AccessToken.new(client, auth.token)

xy = GoogleContactsApi::User.new(oauth2_object)

@x = xy.contacts('orderby' => 'lastmodified', 'sortorder' => 'descending')

This works great but after an hour breaks as the token expires and needs to refresh. I'm working to get the OAuth2 Client to refresh the token per the docs like so:

auth = User.first.authentications.first

client = OAuth2::Client.new('removed', 'removed', :site => 'https://accounts.google.com')

oauth2_object = OAuth2::AccessToken.new(client, auth.token, :refresh_token => auth.refresh_token)

oauth2_object.refresh!

xy = GoogleContactsApi::User.new(oauth2_object)

@x = xy.contacts('orderby' => 'lastmodified', 'sortorder' => 'descending')

Notice how I'm passing refresh_token to OAuth2::AccessToken.new per the docs: http://www.rubydoc.info/github/intridea/oauth2/OAuth2%2FAccessToken%3Ainitialize

Problem is this is erring with "A refresh_token is not available"

Any idea why?

Thanks

相关阅读:
Top