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
Merge requests
!3
WP110 #1270: Added Feide OpenConnectID Client
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
WP110 #1270: Added Feide OpenConnectID Client
1270-wp110-set-up-config-for-feide
into
master
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
stian.kilaas
requested to merge
1270-wp110-set-up-config-for-feide
into
master
4 months ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
098faff6
1 commit,
4 months ago
1 file
+
157
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/Plugin/OpenIDConnectClient/OpenIDConnectFeideClient.php
0 → 100644
+
157
−
0
Options
<?php
namespace
Drupal\uib_feide\Plugin\OpenIDConnectClient
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\GeneratedUrl
;
use
Drupal\Core\Site\Settings
;
use
Drupal\openid_connect
\Plugin\OpenIDConnectClientBase
;
/**
* Feide OpenID Connect client.
*
* @OpenIDConnectClient(
* id = "feide",
* label = @Translation("Feide")
* )
*/
class
OpenIDConnectFeideClient
extends
OpenIDConnectClientBase
{
/**
* {@inheritdoc}
*/
public
function
defaultConfiguration
():
array
{
return
[
'issuer_url'
=>
''
,
'authorization_endpoint'
=>
'https://auth.dataporten.no/oauth/authorization'
,
'token_endpoint'
=>
'https://auth.dataporten.no/oauth/token'
,
'userinfo_endpoint'
=>
'https://auth.dataporten.no/openid/userinfo'
,
'end_session_endpoint'
=>
''
,
'scopes'
=>
[
'openid'
,
'email'
,
'userid-feide'
],
]
+
parent
::
defaultConfiguration
();
}
/**
* {@inheritdoc}
*/
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
):
array
{
$form
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
$form
[
'authorization_endpoint'
]
=
[
'#title'
=>
$this
->
t
(
'Authorization endpoint'
),
'#default_value'
=>
$this
->
configuration
[
'authorization_endpoint'
],
'#disabled'
=>
TRUE
,
'#type'
=>
'url'
,
];
$form
[
'token_endpoint'
]
=
[
'#title'
=>
$this
->
t
(
'Token endpoint'
),
'#default_value'
=>
$this
->
configuration
[
'token_endpoint'
],
'#disabled'
=>
TRUE
,
'#type'
=>
'url'
,
];
$form
[
'userinfo_endpoint'
]
=
[
'#title'
=>
$this
->
t
(
'UserInfo endpoint'
),
'#default_value'
=>
$this
->
configuration
[
'userinfo_endpoint'
],
'#disabled'
=>
TRUE
,
'#type'
=>
'url'
,
];
$form
[
'scopes'
]
=
[
'#title'
=>
$this
->
t
(
'Scopes'
),
'#type'
=>
'textfield'
,
'#default_value'
=>
implode
(
' '
,
$this
->
configuration
[
'scopes'
]),
'#disabled'
=>
TRUE
,
];
$form
[
'client_id'
]
=
[
'#title'
=>
$this
->
t
(
'Client ID'
),
'#type'
=>
'textfield'
,
'#default_value'
=>
'Client ID coming from .env file'
,
'#disabled'
=>
TRUE
,
];
$form
[
'client_secret'
]
=
[
'#title'
=>
$this
->
t
(
'Client secret'
),
'#type'
=>
'textfield'
,
'#default_value'
=>
'Client Secret coming from .env file'
,
'#disabled'
=>
TRUE
,
];
return
$form
;
}
/**
* {@inheritdoc}
*/
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
):
void
{
$configuration
=
$form_state
->
getValues
();
if
(
!
empty
(
$configuration
[
'scopes'
]))
{
$this
->
setConfiguration
([
'scopes'
=>
explode
(
' '
,
$configuration
[
'scopes'
])]);
}
parent
::
submitConfigurationForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
getClientScopes
():
?array
{
return
$this
->
configuration
[
'scopes'
];
}
/**
* {@inheritdoc}
*/
public
function
getEndpoints
()
:
array
{
return
[
'authorization'
=>
$this
->
configuration
[
'authorization_endpoint'
],
'token'
=>
$this
->
configuration
[
'token_endpoint'
],
'userinfo'
=>
$this
->
configuration
[
'userinfo_endpoint'
],
'end_session'
=>
$this
->
configuration
[
'end_session_endpoint'
],
];
}
/**
* {@inheritdoc}
*/
protected
function
getRequestOptions
(
string
$authorization_code
,
string
$redirect_uri
):
array
{
$client_id
=
Settings
::
get
(
'feide_client_id'
);
$client_secret
=
Settings
::
get
(
'feide_client_secret'
);
if
(
empty
(
$client_id
)
||
empty
(
$client_secret
))
{
throw
new
\RuntimeException
(
'Client ID or Client Secret is not set in the .env file'
);
}
return
[
'form_params'
=>
[
'code'
=>
$authorization_code
,
'client_id'
=>
$client_id
,
'client_secret'
=>
$client_secret
,
'redirect_uri'
=>
$redirect_uri
,
'grant_type'
=>
'authorization_code'
,
],
'headers'
=>
[
'Accept'
=>
'application/json'
,
],
];
}
/**
* {@inheritdoc}
*/
protected
function
getUrlOptions
(
string
$scope
,
GeneratedUrl
$redirect_uri
):
array
{
$client_id
=
Settings
::
get
(
'feide_client_id'
);
if
(
empty
(
$client_id
))
{
throw
new
\RuntimeException
(
'Client ID is not set in the .env file'
);
}
return
[
'query'
=>
[
'client_id'
=>
$client_id
,
'response_type'
=>
'code'
,
'scope'
=>
$scope
,
'redirect_uri'
=>
$redirect_uri
->
getGeneratedUrl
(),
'state'
=>
$this
->
stateToken
->
generateToken
(),
],
];
}
}
Loading