-
Notifications
You must be signed in to change notification settings - Fork 163
Open
Labels
type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.
Description
I am trying to figure out how to update the access token using the refresh token which I got during the initial authorization. I tried multiple ways to do this but I always receive:
Signet::AuthorizationError: Authorization failed. Server message:
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
The main method to which I have been adding changes to is:
def refresh_google_calendar
@service = Google::Apis::CalendarV3::CalendarService.new
@service.authorization = google_secret
# Attempts to refresh access token if already expired.
@service.authorization.refresh! if @user.google_expires_at < Time.current
end
def google_secret
Signet::OAuth2::Client.new(refresh_options)
end
def refresh_options
{ token_credential_uri: 'https://oauth2.googleapis.com/token',
access_token: @user.google_token,
expires_at: @user.google_expires_at,
refresh_token: @user.google_refresh_token,
client_id: ENV.fetch('GOOGLE_CLIENT_ID'),
client_secret: ENV.fetch('GOOGLE_CLIENT_SECRET') }
endI tried another variation of the refresh_options as:
def refresh_options
{ refresh_token: @user.google_refresh_token,
token_credential_uri: 'https://oauth2.googleapis.com/token',
client_id: ENV.fetch('GOOGLE_CLIENT_ID'),
client_secret: ENV.fetch('GOOGLE_CLIENT_SECRET') }
endAlso attempted using Google::Auth::UserRefreshCredentials as explained here but I still get the invalid_grant error.
I do know that my Client ID and Client Secret work because I use the same for the initial authorization request.
I would appreciate any help in figuring this out.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: questionRequest for information or clarification. Not an issue.Request for information or clarification. Not an issue.