使用 google oauth 2 策略范围失败的 OmniAuth

发布于 12-21 10:23 字数 479 浏览 3 评论 0原文

我正在努力使用 OmniAuthgoogle-oauth-2 策略从 Google 获取日历数据。

如果我没有在范围字段中添加任何内容,它就可以正常工作,并且我会获得默认信息,而无需验证/失败消息,并且我可以正常使用该应用程序。

然而,当我添加范围时,如下例所示,我收到“auth/failure?message=invalid_credentials”。

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], { :scope => 'https://www.google.com/calendar/feeds/' }
end

有什么我遗漏的或者我应该改变的吗?

I'm working on getting calendar data from google using OmniAuth and the google-oauth-2 strategy.

If I put nothing into the scope field it works fine and I get the default info without the auth/failure message and I can use the app normally.

However the moment I add a scope, as in the example below, I get an "auth/failure?message=invalid_credentials".

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], { :scope => 'https://www.google.com/calendar/feeds/' }
end

Is there something I'm missing or something I should change?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北笙凉宸2024-12-28 10:23:07

google-oauth-2 策略作者发来的一封快速电子邮件指出了以下内容:

如果您不包含配置文件范围,则无法进行身份验证。

通过将 userinfo.emailuserinfo.profile (以及日历范围)添加到逗号分隔的 :scope 列表中,我能够修复问题。

例子:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], 
           { :scope => 'userinfo.email, userinfo.profile, https://www.googleapis.com/auth/calendar' }
end

A quick e-mail from the google-oauth-2 strategy author pointed out the following:

If you don't include the profile scopes, it fails to authenticate.

By adding userinfo.email and userinfo.profile (along with the calendar scope) to the comma separated :scope list I was able to fix the problem.

Example:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], 
           { :scope => 'userinfo.email, userinfo.profile, https://www.googleapis.com/auth/calendar' }
end
和我恋爱吧2024-12-28 10:23:07

有趣的是,这对我不起作用。
我能够使其工作,从范围中删除逗号:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], 
    { :scope => 'https://www.googleapis.com/auth/docs https://www.googleapis.com/auth/userinfo.profile' }
end

Funny, this didn't work for me.
I was able to make it work, removing the comma from the scope:

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :google_oauth2, ENV['TEST_KEY'], ENV['TEST_SECRET'], 
    { :scope => 'https://www.googleapis.com/auth/docs https://www.googleapis.com/auth/userinfo.profile' }
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文