Skip to content
Snippets Groups Projects
Commit a67bab16 authored by Rafael dos Santos Silva's avatar Rafael dos Santos Silva Committed by GitHub
Browse files

Merge pull request #8 from discourse/group-sync

Group sync
parents f4d5f139 bd7b65c2
No related branches found
No related tags found
No related merge requests found
......@@ -63,13 +63,43 @@ class SamlAuthenticator < ::Auth::OAuth2Authenticator
result.username = ''
end
if GlobalSetting.try(:saml_omit_username) && result.user.blank?
result.omit_username = true
end
sync_groups(result.user, auth) unless result.user.blank?
result.extra_data = { saml_user_id: uid }
result
end
def after_create_account(user, auth)
::PluginStore.set("saml", "saml_user_#{auth[:extra_data][:saml_user_id]}", {user_id: user.id })
sync_groups(user, auth)
end
def sync_groups(user, auth)
return unless GlobalSetting.try(:saml_sync_groups) && GlobalSetting.try(:saml_sync_groups_list) && auth.extra.present? && auth.extra[:raw_info].present?
total_group_list = GlobalSetting.try(:saml_sync_groups_list).split('|')
user_group_list = auth.extra[:raw_info].attributes['memberOf']
groups_to_add = Group.where(name: total_group_list & user_group_list)
groups_to_add.each do |group|
group.add user
end
groups_to_remove = Group.where(name: total_group_list - user_group_list)
groups_to_remove.each do |group|
group.remove user
end
end
end
if request_method == 'post'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment