当前位置:  开发笔记 > 编程语言 > 正文

Rails,Devise和Facebook Oauth:request.env ["omniauth.auth"]是零

如何解决《Rails,Devise和FacebookOauth:request.env["omniauth.auth"]是零》经验,为你挑选了0个好方法。

我在我的rails应用程序中使用Facebook Oauth和Devise.我成功地进入了facebook登录页面,但随后在回调操作中出错.跟踪它以request.env["omniauth.auth"]返回nil我的回调动作.

的Gemfile:

gem 'devise'
gem 'omniauth'
gem 'omniauth-facebook'

路线:

  devise_scope :user do
    get '/users/auth/facebook/callback', to: 'users/omniauth_callbacks#facebook'
  end

  resources :users
  devise_for :users, path: '', path_names: { sign_up: 'register', sign_in: 'login', sign_out: 'logout'}, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

初始化/ devise.rb:

config.omniauth :facebook, Figaro.env.facebook_key, Figaro.env.facebook_secret,
                scope: 'email,public_profile',
                callback_url: Figaro.env.facebook_callback_url

User.rb:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, 
          :recoverable, :rememberable, :trackable, :confirmable, :validatable,
          :omniauthable, :omniauth_providers => [:facebook]

omn​​iauth_callbacks_controller.rb:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController

 def facebook

    @user = User.from_omniauth(request.env["omniauth.auth"])
     request.env["omniauth.auth"]   ## <<=== this is nil

知道我request.env["omniauth.auth"]回来的原因nil吗?

推荐阅读
跟我搞对象吧
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有