Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4612

How to refresh access_token for the Google API with Ruby client?

$
0
0

I have a working app (Rails) that authenticates a user and saves her tokens in a Redis store.

If I've understood it correctly, using googleauth together with google-api-client, the client object will refresh the access token (by itself) as needed? This doesn't happen though, the token expires and some time after that I get a 403 error.

If the problem is on my side - can/should I invoke a new access_token manually, and if so how do I do that?

The code I've used is mainly taken from the quickstart guide.

gem 'google-api-client', require: 'google/apis/calendar_v3'def authorizer  scope = Google::Apis::CalendarV3::AUTH_CALENDAR  client_id = Google::Auth::ClientId.from_hash(JSON.parse(ENV['GOOGLE_CLIENT_SECRETS']))  token_store = Google::Auth::Stores::RedisTokenStore.new(redis: $redis)  authorizer = Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store)  authorizerenddef authenticate_the_user  user_id = "1"  credentials = authorizer.get_credentials(user_id)  redirect_to authorizer.get_authorization_url(login_hint: user_id, request: request, base_url: "http://localhost:3000")enddef handle_callback  credentials = authorizer.get_and_store_credentials_from_code(user_id: "1", code: params[:code], base_url: "http://localhost:3000/oauth2callback")end

Viewing all articles
Browse latest Browse all 4612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>