Reputation: 383
So I have a web app with ruby on rails that connects to google drive's API. Up until now, it used to receive the refresh token, since one of the paramenters I was using was offline. But recently it stopped getting it. The url that is being sent is this:
Redirected to https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=ID&options=%7B:access_type=%3E%22offline%22,%20:approval_prompt=%3E%22force%22%7D&redirect_uri=http://localhost:3000/oauth2callbackdrive&response_type=code&scope=https://www.googleapis.com/auth/drive%20https://www.googleapis.com/auth/userinfo.email
The code that is redirecting to the URI has this:
client = Google::APIClient.new
client.authorization.client_id = GOOGLE_CLIENT_ID
client.authorization.client_secret = GOOGLE_CLIENT_SECRET
client.authorization.scope = SCOPES
client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI
auth_url = client.authorization.authorization_uri(:options => {:access_type => :offline, :approval_prompt => :force}.to_s)
redirect_to auth_url.to_s
On the callback function I have this:
client = Google::APIClient.new
client.authorization.client_id = GOOGLE_CLIENT_ID
client.authorization.client_secret = GOOGLE_CLIENT_SECRET
client.authorization.scope = SCOPES
client.authorization.redirect_uri = GOOGLE_CLIENT_REDIRECT_URI
client.authorization.code = params['code']
client.authorization.fetch_access_token!
And on the same function I insert into the database:
CloudAccount.create(username: username,access_token:client.authorization.access_token, refresh_token:client.authorization.refresh_token,register_id:userID,cloud_name:'drive')
Problem is, the client.authorization.refresh_token, which had a value before, now is returning empty and so it's being inserted into the DB as NULL. Which affects uploads/refresh/downloads when the access_token expires.
What can I do or what am I doing wrong?
Thanks.
Upvotes: 1
Views: 385
Reputation: 113
I was having a similar issue (Getting a refresh token from google api). I think if you use:
prompt='select_account consent'
then that forces a new approval screen and you get a new refresh_token.
Reference: https://developers.google.com/identity/protocols/OAuth2UserAgent
Upvotes: 2