Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Discourse SAML
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Giacomo Vercesi
Discourse SAML
Commits
a67bab16
Commit
a67bab16
authored
7 years ago
by
Rafael dos Santos Silva
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #8 from discourse/group-sync
Group sync
parents
f4d5f139
bd7b65c2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugin.rb
+30
-0
30 additions, 0 deletions
plugin.rb
with
30 additions
and
0 deletions
plugin.rb
+
30
−
0
View file @
a67bab16
...
...
@@ -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'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment