3

我正在使用“omniauth-google-oauth2”登录谷歌并仔细按照此处的所有说明进行操作

   https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview

但我上面有错误。

我的路线

    devise_for :users, :controllers => {
      :omniauth_callbacks => "users/omniauth_callbacks"

    }

设计.rb代码

  config.omniauth :google_oauth2, "863625299460- 420n6c7lvad91dfvko60uamtvtr6huhf.apps.googleusercontent.com", "dcvA2aZRZi27KCQjWTYP30pw", {  access_type: "offline", approval_prompt: "" }

omn​​iauth 回调控制器代码

     def google_oauth2
       #@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
       binding.pry #control not coming here
     end

回调后我在下面有错误。看截图

    https://github.com/zquestz/omniauth-google-oauth2/issues/52
4

3 回答 3

1

This looks like a route issue. If you do "rake routes | grep auth" what do you see?

于 2013-04-15T16:55:49.633 回答
0

我遇到了与您描述的完全相同的问题。确保您需要 config/initializers/deviser.rb 中的 omniauth-google-oauth2 gem

# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
require "omniauth-google-oauth2"
config.omniauth :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
                                { access_type: "offline", approval_prompt: "force" }

我添加了 devise.rb 文件的整个部分来提供上下文。

于 2013-06-10T15:14:25.747 回答
0

已经很晚了,但这个答案可能对其他人有用

如果您devise用于身份验证,则默认情况下设计会在路由文件中生成路由,devise_for :users并且您的omniouth_callback路由应高于默认devise路由,以便覆盖默认设计路由。

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"}
  devise_for :users
于 2015-08-15T17:47:21.043 回答