mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
major refactor of auth, break up the gigantic omniauth controller into sub classes for way better extensibitily
This commit is contained in:
parent
90dddb4395
commit
b52aba15e0
11 changed files with 407 additions and 394 deletions
56
lib/auth/facebook_authenticator.rb
Normal file
56
lib/auth/facebook_authenticator.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class Auth::FacebookAuthenticator < Auth::Authenticator
|
||||
|
||||
def name
|
||||
"facebook"
|
||||
end
|
||||
|
||||
def after_authenticate(auth_token)
|
||||
|
||||
result = Auth::Result.new
|
||||
|
||||
session_info = parse_auth_token(auth_token)
|
||||
facebook_hash = session_info[:facebook]
|
||||
|
||||
result.email = email = session_info[:email]
|
||||
result.name = name = facebook_hash[:name]
|
||||
|
||||
result.extra_info = facebook_hash
|
||||
|
||||
user_info = FacebookUserInfo.where(facebook_user_id: facebook_hash[:facebook_user_id]).first
|
||||
|
||||
if result.user = lookup_user(user_info, email) && !user_info
|
||||
user.create_facebook_user_info! facebook_hash
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def after_create_account(user, auth)
|
||||
data = auth[:extra_data]
|
||||
FacebookUserInfo.create({user_id: user.id}.merge(data))
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def parse_auth_token(auth_token)
|
||||
|
||||
raw_info = auth_token["extra"]["raw_info"]
|
||||
email = auth_token["info"][:email]
|
||||
|
||||
{
|
||||
facebook: {
|
||||
facebook_user_id: auth_token["uid"],
|
||||
link: raw_info["link"],
|
||||
username: raw_info["username"],
|
||||
first_name: raw_info["first_name"],
|
||||
last_name: raw_info["last_name"],
|
||||
email: email,
|
||||
gender: raw_info["gender"],
|
||||
name: raw_info["name"]
|
||||
},
|
||||
email: email,
|
||||
email_valid: true
|
||||
}
|
||||
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue