简体   繁体   English

设计omniauth-github oauth2错误“bad_verification_code”

[英]Devise omniauth-github oauth2 error “bad_verification_code”

I have a Rails 3.1 app with devise 1.5.3 , omniauth 1.0.1 , and omniauth-github 1.0.1 as well. 我有一个Rails 3.1应用程序,配备devise 1.5.3omniauth 1.0.1omniauth-github 1.0.1

config/initializers/devise.rb 配置/初始化/ devise.rb

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

config/routes.rb 配置/ 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. 密钥和密钥设置为Heroku变量,应用程序在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. 单击您发送给Github的链接,进行身份验证,然后使用代码和auth成功的所有信息发送回Github回调路由。

The problem is that it is getting picked up by the failure method of the users/omniiauth_callbacks controller. 问题是它被users/omniiauth_callbacks控制器的失败方法所users/omniiauth_callbacks I added some put statements to see what the env['omniauth'] was getting sent back with. 我添加了一些put语句来查看env['omniauth']被送回的内容。

env['omniauth.auth'] has all of the info from Github that it is supposed to. env['omniauth.auth']拥有来自Github的所有信息。

env['omniauth.error'].response however is a an OAuth2::Response with a lot of info, the important parts being: env['omniauth.error'].response是一个带有大量信息的OAuth2::Response ,重要的部分是:

@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 . 我想知道这篇文章是否仍然有效,因为Github现在有了新的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. 有可能只将我需要的代码放在回调控制器的失败方法中,但这有点肮脏和hackish。

Any suggestions would be much appreciated. 任何建议将不胜感激。

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. 我不确定这是否会有所帮助,但仅在昨天,当我尝试使用omniauth gem与github进行身份验证时,我有点得到同样的错误。

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. 最后,我最终以github的方式将client_id,client_secret和redirect_uri发送到/github.com/oauth/authorize并在redirect_uri上获得了回调。

Heres the link 继承人的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM