Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UiB Feide userinfo modification
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT-division Public
Drupal
Modules
UiB Feide userinfo modification
Commits
2c1808e5
Commit
2c1808e5
authored
3 months ago
by
Are Johannessen
Browse files
Options
Downloads
Patches
Plain Diff
WP110 Refactor uib_feide_openid_connect_pre_authorize
parent
098faff6
Branches
refactor-uib-feide-openid-connect-pre-authorize
No related tags found
1 merge request
!5
WP110 Refactor uib_feide_openid_connect_pre_authorize
Pipeline
#271643
passed
2 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
uib_feide.module
+30
-28
30 additions, 28 deletions
uib_feide.module
with
30 additions
and
28 deletions
uib_feide.module
+
30
−
28
View file @
2c1808e5
...
...
@@ -28,40 +28,42 @@ function uib_feide_openid_connect_pre_authorize($account, array $context) : bool
// Retrieve the 'uib_feide' settings.
$config
=
Drupal
::
config
(
'uib_feide.user_control_settings'
);
if
(
$config
->
get
(
'domains_allowed'
)
!==
''
)
{
// Get the SCIM data for the user.
$api_service
=
Drupal
::
service
(
'plugin.manager.api_connector'
);
$scim_connector
=
$api_service
->
createInstance
(
'scim'
);
$scim_data
=
$scim_connector
->
fetchScimUser
(
$context
[
'userinfo'
][
'email'
]);
if
(
$scim_data
!==
NULL
)
{
$roles
=
$scim_data
->
getRoles
();
if
(
$config
->
get
(
'domains_allowed'
)
===
''
)
{
return
TRUE
;
}
// Check if the user has the correct domain.
$domains_allowed
=
explode
(
"
\r
"
,
str_replace
([
"
\r\n
"
,
"
\n
"
],
"
\r
"
,
$config
->
get
(
'domains_allowed'
)
?:
''
));
$email_account_for_new_user
=
$context
[
'userinfo'
][
'email'
];
// Get the SCIM data for the user.
$api_service
=
Drupal
::
service
(
'plugin.manager.api_connector'
);
$scim_connector
=
$api_service
->
createInstance
(
'scim'
);
$scim_data
=
$scim_connector
->
fetchScimUser
(
$context
[
'userinfo'
][
'email'
]);
if
(
$scim_data
===
FALSE
)
{
return
TRUE
;
}
$roles
=
$scim_data
->
getRoles
();
if
(
str_contains
(
$email_account_for_new_user
,
'@'
))
{
$domain_for_new_user
=
explode
(
'@'
,
$email_account_for_new_user
)[
1
];
if
(
in_array
(
$domain_for_new_user
,
$domains_allowed
))
{
$domain_matches
=
TRUE
;
}
}
// Check if the user has the correct domain.
$domains_allowed
=
explode
(
"
\r
"
,
str_replace
([
"
\r\n
"
,
"
\n
"
],
"
\r
"
,
$config
->
get
(
'domains_allowed'
)
?:
''
));
$email_account_for_new_user
=
$context
[
'userinfo'
][
'email'
];
// Check if the user has the correct variable.
$roles_allowed
=
explode
(
"
\r
"
,
str_replace
([
"
\r\n
"
,
"
\n
"
],
"
\r
"
,
$config
->
get
(
'roles_allowed'
)
?:
''
));
if
(
str_contains
(
$email_account_for_new_user
,
'@'
))
{
$domain_for_new_user
=
explode
(
'@'
,
$email_account_for_new_user
)[
1
];
if
(
in_array
(
$domain_for_new_user
,
$domains_allowed
))
{
$domain_matches
=
TRUE
;
}
}
// Check each setting.
foreach
(
$roles_allowed
as
$role
)
{
if
(
in_array
(
$role
,
$roles
))
{
$role_matches
=
TRUE
;
break
;
}
}
// Check if the user has the correct variable.
$roles_allowed
=
explode
(
"
\r
"
,
str_replace
([
"
\r\n
"
,
"
\n
"
],
"
\r
"
,
$config
->
get
(
'roles_allowed'
)
?:
''
));
// If both the domain and role matches, then proceed to log in.
return
$domain_matches
&&
$role_matches
;
// Check each setting.
foreach
(
$roles_allowed
as
$role
)
{
if
(
in_array
(
$role
,
$roles
))
{
$role_matches
=
TRUE
;
break
;
}
}
return
TRUE
;
// If both the domain and role matches, then proceed to log in.
return
$domain_matches
&&
$role_matches
;
}
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