Oauth2 google-api-ruby-client:如何将批准提示设置为自动? [英] Oauth2 google-api-ruby-client: How to set Approval Prompt to Auto?

查看:92
本文介绍了Oauth2 google-api-ruby-client:如何将批准提示设置为自动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: 如何将批准提示设置为自动?默认为'approval_prompt = force'

Question: How to set the Approval Prompt to Auto? It defaults to 'approval_prompt=force'

代码: 我正在这样设置客户.

Code: I am setting up the client like this.

   @client = Google::APIClient.new(
     :authorization => :oauth_2,
     :host => 'www.googleapis.com',
     :http_adapter => HTTPAdapter::NetHTTPAdapter.new
   )   
   @client.authorization.client_id = 'xxxx.apps.googleusercontent.com'
   @client.authorization.client_secret = 'xxxx'

上下文:Google OAuth2

Context: Google OAuth2

客户端库:google-api-ruby-client

Client Library: google-api-ruby-client

参考:php客户端的相同问题:
Google+ OAuth API存储区并在首次登录和授权后检索令牌

Reference: Same question for the php client :
Google+ OAuth API store and retrieve tokens after first login and authorization

Signet文档.我找不到rovaling_prompt设置器 http://signet.rubyforge.org/api/Signet/OAuth2/Client. html

Signet Documentation. I can't find the approval_prompt setter http://signet.rubyforge.org/api/Signet/OAuth2/Client.html

推荐答案

这就是我解决问题的方式.

This is how I solved the problem.

我编写了一个单独的帮助程序方法,该方法将生成Google OAuth URI

I wrote a separate helper method that will generate the Google OAuth URI

def build_auth_uri
return @client.authorization.authorization_uri(
 :approval_prompt => :auto
).to_s 

结束

接下来,我不再直接在我的视图中引用Google OAuth URI,而是调用了帮助程序.

Next, instead of referring to Google OAuth URI directly in my view, I called the helper.

就成功了.

这篇关于Oauth2 google-api-ruby-client:如何将批准提示设置为自动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆