停止从谷歌的API获取刷新令牌

编程入门 行业动态 更新时间:2024-10-27 23:22:06
本文介绍了停止从谷歌的API获取刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 因此,我有一个网络应用程序,通过轨道上的ruby连接到谷歌驱动器的API。直到现在,它用来接收刷新标记,因为我使用的参数之一是离线的。但最近它停止了。正在发送的网址是:

重定向到accounts.google/o/oauth2/auth ?ACCESS_TYPE =离线&安培; CLIENT_ID = ID&安培;选项=%7B:ACCESS_TYPE =%3E%22offline%22%20:approval_prompt =%3E%22force%22%7D&安培; REDIRECT_URI = HTTP://本地主机:3000 / oauth2callbackdrive&安培; RESPONSE_TYPE = code& scope = https://www.googleapis/auth/drive%20https://www.googleapis/auth/userinfo.email

重定向到URI的代码有:

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

在通话中返回函数我有这个:

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!

然后在数据库中插入相同的函数:

CloudAccount.create(用户名:username,access_token:client.authorization.access_token,refresh_token:client.authorization.refresh_token,register_id:userID,cloud_name:'drive')

问题是,之前具有值的client.authorization.refresh_token现在正在返回空值,所以它是被作为NULL插入到DB中。这会在access_token过期时影响上传/刷新/下载。

我该做什么或者我做错了什么?

感谢。 解决方案

我遇到类似问题(从谷歌API获取刷新令牌)。我想如果你使用: prompt ='select_account consent'

然后强制一个新的批准屏幕上显示新的refresh_token。

noreferrer> developers.google/identity/protocols/OAuth2UserAgent

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 accounts.google/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=localhost:3000/oauth2callbackdrive&response_type=code&scope=www.googleapis/auth/drive%20www.googleapis/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.

解决方案

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: developers.google/identity/protocols/OAuth2UserAgent

更多推荐

停止从谷歌的API获取刷新令牌

本文发布于:2023-11-26 15:37:39,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!