6
6

More than 5 years have passed since last update.

[Devise] Omniauth を利用して、Facebook,Twitterなどでログインするとき、parameterを渡す方法

Posted at

はじめに

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

References

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6