はじめに
Deviseを使ってFacebookやTwitter, Linkedinなどでログインしたいとき、適当な引数を渡したい場合の対処法メモです。
書き方
渡し方
結構シンプルで :params に入れるといいだけです。
omniauth_authorize_path(:user, :facebook, var1: 'value1', var2: 'value2' )
/users/auth/facebook?var1=value1&var2=value2
example
/users/auth/facebook?name=hoge
受け取り方
request.env['omniauth.params']
---
{"var1"=>"value1"}
example_callback_controller
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def facebook
@user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user, request.env["omniauth.params"])
・
・
end
end
example_model
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :lockable, :timeoutable
devise :database_authenticatable, :registerable, :confirmable, :omniauthable,
:recoverable, :rememberable, :trackable, :validatable
def self.find_for_facebook_oauth(auth, signed_in_resource=nil, params_hash)
・
・
・
end
end