我正在使用带有Angular前端的Rails后端(API作用域为'/ api') . 我正在尝试使用ng-token-auth和devise-token-auth合并基于令牌的授权 .

我使用常规注册登录工作,但我似乎无法使用oAuth . 我也不明白如何调试问题 .

我有一个使用密钥/密钥设置的Github应用程序 . 在我的前端,有一个按钮,它将使用$ auth.authenticate('github')中内置的ng-token-auth .

会发生什么情况是页面将重定向到github,请求权限,然后重定向回我的网站(虽然新标签,而不是原始标签)并加载主页 .

auth没有检查所有路由,回调网址,并按照https://github.com/lynndylanhurley/devise_token_authhttps://github.com/lynndylanhurley/ng-token-auth上的所有说明进行操作,但我可以't figure out what'出错或如何诊断它 .

如果我记录$ auth.authenticate响应,我会得到一个错误,即auth无效(“用户取消登录”),但这似乎更像是超时的事情?

有没有办法查看标头中是否实际发送了任何令牌?有什么潜在的问题?我也试过Twitter

(setting the host to either http://127.0.0.1:3000 or http://localhost:3000)

编辑:这是http请求在终端中的样子

Started GET "/omniauth/github?     auth_origin_url=http%3A%2F%2Flocalhost%3A3000%2Fsign_in&favorite_color=blue&resource_class=User" for      127.0.0.1 at 2014-12-29 18:33:55 -0800
I, [2014-12-29T18:33:55.295507 #46466]  INFO -- omniauth: (github) Request phase initiated.


Started GET "/omniauth/github/callback?code=3c03dbb28c2bb0bc8d36&state=5ce4e8bae5f9671ffe521ceeb54a14eb42c3b2866cd79b8e" for 127.0.0.1 at 2014-12-29 18:33:55 -0800
I, [2014-12-29T18:33:55.692405 #46466]  INFO -- omniauth: (github) Callback phase initiated.
Processing by HomeController#index as HTML
Parameters: {"code"=>"3c03dbb28c2bb0bc8d36", "state"=>"5ce4e8bae5f9671ffe521ceeb54a14eb42c3b2866cd79b8e"}
Rendered home/index.html.erb within layouts/application (0.0ms)
Completed 200 OK in 117ms (Views: 116.6ms | ActiveRecord: 0.0ms)

编辑:

好的,所以我开始工作了 . 的种类 . 我的rails路由文件有这行:

root to: "home#index", anchor: false

我删除了“anchor:false”,现在omniauth的回调成功了 . 然而,这使得轨道/角度路线不能100%工作/玩得很好 . 例如,如果我转到localhost:3000,然后单击指向/ sign_in的链接,它将转到正确的页面 . 如果我尝试直接在浏览器中访问localhost:3000 / sign_in,rails会抱怨缺少路由...

好的解决了!

所以我只是在rails路由文件中重新创建了回调路由并且它工作正常 . 得到“/ omniauth /:provider / callback”=>“devise_token_auth / omniauth_callbacks#redirect_callbacks”

当我早先检查了rails路由时,它有确切的路由,但它是在定义了根路由之后 . 我不知道如何修复它而不在rails路由中明确定义它 .