设计omniauth-github oauth2错误“bad_verification_code”

发布于 2024-12-29 19:13:15 字数 1213 浏览 3 评论 0原文

我有一个带有 devise 1.5.3omniauth 1.0.1omniauth-github 1.0.1 的 Rails 3.1 应用程序。

config/initializers/devise.rb

config.omniauth :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']

config/routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

密钥和秘密设置为 Heroku 变量,并且应用程序在 Github 上注册。单击链接,您将被发送到 Github,进行身份验证,然后发送回 Github 回调路由,其中​​包含代码和身份验证成功的所有信息。

问题是它被 users/omniiauth_callbacks 控制器的失败方法获取。我添加了一些 put 语句来查看 env['omniauth'] 被发送回的内容。

env['omniauth.auth'] 拥有来自 Github 的所有应有信息。

然而 env['omniauth.error'].response 是一个包含大量信息的 OAuth2::Response ,重要的部分是:

@parsed={"error"=>"bad_verification_code"}, @error=#<OAuth2::Error: OAuth2::Error>

我想知道这篇文章是否是仍然有效,因为 Github 现在有了新的 v3 API

可以将我需要的代码放在回调控制器的失败方法中,但这感觉有点肮脏和黑客。

任何建议将不胜感激。

I have a Rails 3.1 app with devise 1.5.3, omniauth 1.0.1, and omniauth-github 1.0.1 as well.

config/initializers/devise.rb

config.omniauth :github, ENV['GITHUB_KEY'], ENV['GITHUB_SECRET']

config/routes.rb

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
  get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru'
end

The key and secret are set up as Heroku variables and the application is registered on Github. Clicking the link you are sent to Github, authenticated and then sent back to the Github callback route with the code and all the info that the auth succeeded.

The problem is that it is getting picked up by the failure method of the users/omniiauth_callbacks controller. I added some put statements to see what the env['omniauth'] was getting sent back with.

env['omniauth.auth'] has all of the info from Github that it is supposed to.

env['omniauth.error'].response however is a an OAuth2::Response with a lot of info, the important parts being:

@parsed={"error"=>"bad_verification_code"}, @error=#<OAuth2::Error: OAuth2::Error>

I am wondering if this post is still valid since Github now has their new v3 API.

It would be possible to just put the code I need in the failure method of the callback controller but that feels kind of dirty and hackish.

Any suggestions would be much appreciated.

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

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

发布评论

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

评论(1

鹤仙姿 2025-01-05 19:13:15

我不太确定这是否有帮助,但就在昨天,当我尝试使用omniauth gem 向 github 进行身份验证时,我遇到了同样的错误。

最后,我最终采用了 github 方式,将 client_id、client_secret 和 redirect_uri 发送到 /github.com/oauth/authorize 并在 redirect_uri 上获得回调。

这是链接

I am not really sure if this is going to help, but only yesterday when i was trying to authenticate with github using omniauth gem, i kinda was getting the same errors.

In the end, i ended up doing it the github way of sending the client_id,client_secret and redirect_uri to /github.com/oauth/authorize and got the callback on the redirect_uri.

Heres the link

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文