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)
authorizer
end
def 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")
end
def handle_callback
credentials = authorizer.get_and_store_credentials_from_code(user_id: "1", code: params[:code], base_url: "http://localhost:3000/oauth2callback")
end