mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
Remove cas auth from core and convert the settings over so they can be used by the plugin
This commit is contained in:
1
Gemfile
1
Gemfile
@ -114,7 +114,6 @@ gem 'omniauth-facebook'
|
|||||||
gem 'omniauth-twitter'
|
gem 'omniauth-twitter'
|
||||||
gem 'omniauth-github'
|
gem 'omniauth-github'
|
||||||
gem 'omniauth-oauth2', require: false
|
gem 'omniauth-oauth2', require: false
|
||||||
gem 'omniauth-cas'
|
|
||||||
gem 'oj'
|
gem 'oj'
|
||||||
# while resolving https://groups.google.com/forum/#!topic/ruby-pg/5_ylGmog1S4
|
# while resolving https://groups.google.com/forum/#!topic/ruby-pg/5_ylGmog1S4
|
||||||
gem 'pg', '0.15.1'
|
gem 'pg', '0.15.1'
|
||||||
|
36
db/migrate/20140211230222_move_cas_settings.rb
Normal file
36
db/migrate/20140211230222_move_cas_settings.rb
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
class MoveCasSettings < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
#As part of removing the build in CAS authentication we should
|
||||||
|
#convert the data over to be used by the plugin.
|
||||||
|
cas_hostname = SiteSetting.where(name: 'cas_hostname').first
|
||||||
|
cas_sso_hostname = SiteSetting.where(name: 'cas_sso_hostname').first
|
||||||
|
if cas_hostname && ! cas_sso_hostname
|
||||||
|
#convert the setting over for use by the plugin
|
||||||
|
cas_hostname.update_attribute(:name, 'cas_sso_hostname')
|
||||||
|
elsif cas_hostname && cas_sso_hostname
|
||||||
|
#copy the setting over for use by the plugin and delete the original setting
|
||||||
|
cas_sso_hostname.update_attribute(:value,cas_hostname.value)
|
||||||
|
cas_hostname.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
cas_domainname = SiteSetting.where(name: 'cas_domainname').first
|
||||||
|
cas_sso_email_domain = SiteSetting.where(name: 'cas_sso_email_domain').first
|
||||||
|
if cas_domainname && ! cas_sso_email_domain
|
||||||
|
#convert the setting over for use by the plugin
|
||||||
|
cas_domainname.update_attribute(:name, 'cas_sso_email_domain')
|
||||||
|
elsif cas_domainname && cas_sso_email_domain
|
||||||
|
#copy the setting over for use by the plugin and delete the original setting
|
||||||
|
cas_sso_email_domain.update_attribute(:value,cas_domainname.value)
|
||||||
|
cas_domainname.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
cas_logins = SiteSetting.where(name: 'cas_logins').first
|
||||||
|
if cas_logins
|
||||||
|
cas_logins.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
#remove the unused table
|
||||||
|
drop_table :cas_user_infos
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -6,4 +6,3 @@ require_dependency 'auth/facebook_authenticator'
|
|||||||
require_dependency 'auth/open_id_authenticator'
|
require_dependency 'auth/open_id_authenticator'
|
||||||
require_dependency 'auth/github_authenticator'
|
require_dependency 'auth/github_authenticator'
|
||||||
require_dependency 'auth/twitter_authenticator'
|
require_dependency 'auth/twitter_authenticator'
|
||||||
require_dependency 'auth/cas_authenticator'
|
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
class Auth::CasAuthenticator < Auth::Authenticator
|
|
||||||
|
|
||||||
def name
|
|
||||||
'cas'
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_authenticate(auth_token)
|
|
||||||
result = Auth::Result.new
|
|
||||||
|
|
||||||
email = auth_token[:info][:email] if auth_token[:info]
|
|
||||||
email ||= if SiteSetting.cas_domainname.present?
|
|
||||||
"#{auth_token[:extra][:user]}@#{SiteSetting.cas_domainname}"
|
|
||||||
else
|
|
||||||
auth_token[:extra][:user]
|
|
||||||
end
|
|
||||||
|
|
||||||
result.email = email
|
|
||||||
result.email_valid = true
|
|
||||||
|
|
||||||
result.username = username = auth_token[:extra][:user]
|
|
||||||
|
|
||||||
result.name = name = if auth_token[:info] && auth_token[:info][:name]
|
|
||||||
auth_token[:info][:name]
|
|
||||||
else
|
|
||||||
auth_token["uid"]
|
|
||||||
end
|
|
||||||
|
|
||||||
cas_user_id = auth_token["uid"]
|
|
||||||
|
|
||||||
result.extra_data = {
|
|
||||||
cas_user_id: cas_user_id
|
|
||||||
}
|
|
||||||
|
|
||||||
user_info = CasUserInfo.where(:cas_user_id => cas_user_id ).first
|
|
||||||
|
|
||||||
result.user = user_info.try(:user)
|
|
||||||
result.user ||= User.where(email: email).first
|
|
||||||
# TODO, create CAS record ?
|
|
||||||
|
|
||||||
result
|
|
||||||
end
|
|
||||||
|
|
||||||
def register_middleware(omniauth)
|
|
||||||
omniauth.provider :cas,
|
|
||||||
:host => SiteSetting.cas_hostname
|
|
||||||
end
|
|
||||||
end
|
|
Reference in New Issue
Block a user