Omniauth && 设计无路由

Omniauth && devise no route

我正在尝试使用 omniauth 登录社交网络。 我用这个 wiki 但我没有成功

有我的代码:

Routes.rb

 get '/auth/:provider/callback', to: 'auth#create'

我的授权控制器:

class AuthController < ApplicationController
  def create
    p request.env['omniauth.auth']
  end

  def vkontakte

  end

  def facebook
  end
end

为什么我有路由错误?

No route matches [GET] "/auth/vkontakte"

感谢

首先,我认为您必须在 config/initializers/devise.rb 中进行一些配置。

config.omniauth :vkontakte, APP_ID, APP_SECRET 您需要添加类似

的内容
devise_for :users, controllers: { omniauth_callbacks: "omniauth_callbacks" }

这样你就可以实现

中的方法了
class OmniauthCallbacksController < Devise::OmniauthCallbacksController

  def vkontakte
    # you can do anything you want to do here. Note that you have access to the `request.env["omniauth.auth"]` which holds all the user information you'd require.
  end
end 

还有一件事:如果您检查 devise documentation,您会发现不同的配置选项,但请始终注意不要 overwrite/create AuthController,因为默认情况下 Omniauth 使用的是它,我认为我相信为了使用设计,您应该从 Devise 而不是 ApplicationController.

继承一些东西