-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Description
Environment details
- OS: ubuntu 22.04 (on wsl)
- Ruby version: 3.1.2
- Gem name and version: googleauth 1.3.0
Steps to reproduce
- Get credentials using the library.
- Let credentials expire.
- When making a request using the library with the expired credentials, it doesn't refresh the access token, causing invalid token response.
Code example
class GoogleCalendar
def self.authorizer
@@authorizer ||= begin
client_id = Google::Auth::ClientId.new(Rails.application.credentials.google.client_id, Rails.application.credentials.google.client_secret)
scope = ['https://www.googleapis.com/auth/calendar.events']
token_store = DatabaseTokenStore.new
Google::Auth::WebUserAuthorizer.new(client_id, scope, token_store, '/oauth2/callback')
end
end
endrequire 'googleauth/token_store'
class DatabaseTokenStore < Google::Auth::TokenStore
def load(id)
user = User.find(id)
user.google_oauth2_tokens
end
def store(id, tokens)
user = User.find(id)
user.google_oauth2_tokens = tokens
user.save!
end
def delete(id)
user = User.find(id)
user.google_oauth2_tokens = nil
user.save!
end
end credentials = GoogleCalendar.authorizer.get_credentials(user_id, request)
if credentials.nil?
render plain: 'Google is not connected.'
return
end
service = Google::Apis::CalendarV3::CalendarService.new
service.authorization = credentials
response = service.list_events('an@example.email', time_min: Time.current.iso8601)Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels