ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilAuthProviderOpenIdConnect Class Reference
+ Inheritance diagram for ilAuthProviderOpenIdConnect:
+ Collaboration diagram for ilAuthProviderOpenIdConnect:

Public Member Functions

 __construct (ilAuthCredentials $credentials)
 
 handleLogout ()
 
 doAuthentication (ilAuthStatus $status)
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 
 getLogger ()
 
 getCredentials ()
 
 doAuthentication (ilAuthStatus $status)
 

Private Member Functions

 handleUpdate (ilAuthStatus $status, $user_info)
 
 initClient ()
 

Private Attributes

const OIDC_AUTH_IDTOKEN = 'oidc_auth_idtoken'
 
const ERR_AUTH_FAILED = 'auth_oidc_failed'
 
const ERR_AUTH_WRONG_LOGIN = 'err_wrong_login'
 
readonly ilOpenIdConnectSettings $settings
 
readonly ilLogger $logger
 
readonly ilLanguage $lng
 

Additional Inherited Members

- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, string $a_reason)
 

Detailed Description

Definition at line 23 of file class.ilAuthProviderOpenIdConnect.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderOpenIdConnect::__construct ( ilAuthCredentials  $credentials)

Reimplemented from ilAuthProvider.

Definition at line 35 of file class.ilAuthProviderOpenIdConnect.php.

36 {
37 global $DIC;
39
40 $this->logger = $DIC->logger()->auth();
42 $this->lng = $DIC->language();
43 $this->lng->loadLanguageModule('auth');
44 }
ilAuthCredentials $credentials
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26

References ilAuthProvider\$credentials, $DIC, ILIAS\GlobalScreen\Provider\__construct(), ilOpenIdConnectSettings\getInstance(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ doAuthentication()

ilAuthProviderOpenIdConnect::doAuthentication ( ilAuthStatus  $status)

Implements ilAuthProviderInterface.

Definition at line 69 of file class.ilAuthProviderOpenIdConnect.php.

69 : bool
70 {
71 if (!$this->settings->getActive()) {
73 $status->setTranslatedReason($this->lng->txt(self::ERR_AUTH_FAILED));
74 $this->logger->info('Authentication aborted, OIDC authentication is disabled');
75 return false;
76 }
77
78 try {
79 $oidc = $this->initClient();
80 $oidc->setRedirectURL(ILIAS_HTTP_PATH . '/openidconnect.php');
81
83 if ($proxy->isActive()) {
84 $host = $proxy->getHost();
85 $port = $proxy->getPort();
86 if ($port) {
87 $host .= ':' . $port;
88 }
89 $oidc->setHttpProxy($host);
90 }
91
92 $this->logger->debug(
93 'Redirect url is: ' .
94 $oidc->getRedirectURL()
95 );
96
97 $oidc->addScope($this->settings->getAllScopes());
98 if ($this->settings->getLoginPromptType() === ilOpenIdConnectSettings::LOGIN_ENFORCE) {
99 $oidc->addAuthParam(['prompt' => 'login']);
100 }
101
102 $oidc->authenticate();
103 // user is authenticated, otherwise redirected to authorization endpoint or exception
104
105 $claims = $oidc->getVerifiedClaims();
106 $this->logger->dump($claims, ilLogLevel::DEBUG);
107 $status = $this->handleUpdate($status, $claims);
108
109 // @todo : provide a general solution for all authentication methods
110 //$_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
111
112 if ($this->settings->getLogoutScope() === ilOpenIdConnectSettings::LOGOUT_SCOPE_GLOBAL) {
113 ilSession::set(self::OIDC_AUTH_IDTOKEN, $oidc->getIdToken());
114 }
115 return true;
116 } catch (Exception $e) {
117 $this->logger->warning($e->getMessage());
118 $this->logger->warning((string) $e->getCode());
120 $status->setTranslatedReason($this->lng->txt(self::ERR_AUTH_FAILED));
121 return false;
122 }
123 }
handleUpdate(ilAuthStatus $status, $user_info)
setTranslatedReason(string $a_reason)
Set translated reason.
const int STATUS_AUTHENTICATION_FAILED
setStatus(int $a_status)
Set auth status.
static set(string $a_var, $a_val)
Set a value.
$claims
Definition: ltitoken.php:68

References $claims, Vendor\Package\$e, ilProxySettings\_getInstance(), ilLogLevel\DEBUG, handleUpdate(), initClient(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), ilOpenIdConnectSettings\LOGIN_ENFORCE, ilOpenIdConnectSettings\LOGOUT_SCOPE_GLOBAL, ilSession\set(), ilAuthStatus\setStatus(), ILIAS\Repository\settings(), ilAuthStatus\setTranslatedReason(), and ilAuthStatus\STATUS_AUTHENTICATION_FAILED.

+ Here is the call graph for this function:

◆ handleLogout()

ilAuthProviderOpenIdConnect::handleLogout ( )

Definition at line 46 of file class.ilAuthProviderOpenIdConnect.php.

46 : void
47 {
48 if ($this->settings->getLogoutScope() === ilOpenIdConnectSettings::LOGOUT_SCOPE_LOCAL) {
49 return;
50 }
51
52 $id_token = ilSession::get(self::OIDC_AUTH_IDTOKEN);
53 $this->logger->debug('Logging out with token: ' . $id_token);
54
55 if (isset($id_token) && $id_token !== '') {
56 ilSession::set(self::OIDC_AUTH_IDTOKEN, '');
57 $oidc = $this->initClient();
58 try {
59 $oidc->signOut(
60 $id_token,
61 ILIAS_HTTP_PATH . '/' . ilStartUpGUI::logoutUrl()
62 );
63 } catch (\Jumbojett\OpenIDConnectClientException $e) {
64 $this->logger->warning('Logging out of OIDC provider failed with: ' . $e->getMessage());
65 }
66 }
67 }
static get(string $a_var)
static logoutUrl(array $parameters=[])
Return the logout URL with a valid CSRF token.

References Vendor\Package\$e, ilSession\get(), initClient(), ILIAS\Repository\logger(), ilOpenIdConnectSettings\LOGOUT_SCOPE_LOCAL, ilStartUpGUI\logoutUrl(), ilSession\set(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ handleUpdate()

ilAuthProviderOpenIdConnect::handleUpdate ( ilAuthStatus  $status,
  $user_info 
)
private
Parameters
stdClass$user_info

Definition at line 128 of file class.ilAuthProviderOpenIdConnect.php.

129 {
130 if (!is_object($user_info)) {
131 $this->logger->error('Received invalid user credentials: ');
132 $this->logger->dump($user_info, ilLogLevel::ERROR);
134 $status->setReason(self::ERR_AUTH_WRONG_LOGIN);
135 return $status;
136 }
137
138 $uid_field = $this->settings->getUidField();
139 $ext_account = $user_info->{$uid_field} ?? '';
140
141 if (!is_string($ext_account) || $ext_account === '') {
142 $this->logger->error('Could not determine valid external account, value is empty or not a string.');
143 $this->logger->dump($user_info, ilLogLevel::ERROR);
145 $status->setReason(self::ERR_AUTH_WRONG_LOGIN);
146 return $status;
147 }
148
149 $this->logger->debug('Authenticated external account: ' . $ext_account);
150
153 $ext_account
154 );
155
156 try {
157 $sync = new ilOpenIdConnectUserSync($this->settings, $user_info);
158 $sync->setExternalAccount($ext_account);
159 $sync->setInternalAccount((string) $int_account);
160 $sync->updateUser();
161
162 $user_id = $sync->getUserId();
163 ilSession::set('used_external_auth_mode', ilAuthUtils::AUTH_OPENID_CONNECT);
166 //$_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
169 $status->setReason(self::ERR_AUTH_WRONG_LOGIN);
170 }
171
172 return $status;
173 }
setReason(string $a_reason)
Set reason.
setAuthenticatedUserId(int $a_id)
const int STATUS_AUTHENTICATED
const int AUTH_OPENID_CONNECT
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user

References ilLogLevel\ERROR, ILIAS\Repository\logger(), ilAuthStatus\setReason(), ilAuthStatus\setStatus(), ILIAS\Repository\settings(), and ilAuthStatus\STATUS_AUTHENTICATION_FAILED.

Referenced by doAuthentication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initClient()

ilAuthProviderOpenIdConnect::initClient ( )
private

Definition at line 175 of file class.ilAuthProviderOpenIdConnect.php.

175 : OpenIDConnectClient
176 {
177 $oidc = new OpenIDConnectClient(
178 $this->settings->getProvider(),
179 $this->settings->getClientId(),
180 $this->settings->getSecret()
181 );
182
183 $oidc->setCodeChallengeMethod('S256');
184
185 return $oidc;
186 }

References ILIAS\Repository\settings().

Referenced by doAuthentication(), and handleLogout().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

readonly ilLanguage ilAuthProviderOpenIdConnect::$lng
private

Definition at line 33 of file class.ilAuthProviderOpenIdConnect.php.

◆ $logger

readonly ilLogger ilAuthProviderOpenIdConnect::$logger
private

Definition at line 32 of file class.ilAuthProviderOpenIdConnect.php.

◆ $settings

readonly ilOpenIdConnectSettings ilAuthProviderOpenIdConnect::$settings
private

Definition at line 30 of file class.ilAuthProviderOpenIdConnect.php.

◆ ERR_AUTH_FAILED

const ilAuthProviderOpenIdConnect::ERR_AUTH_FAILED = 'auth_oidc_failed'
private

Definition at line 27 of file class.ilAuthProviderOpenIdConnect.php.

◆ ERR_AUTH_WRONG_LOGIN

const ilAuthProviderOpenIdConnect::ERR_AUTH_WRONG_LOGIN = 'err_wrong_login'
private

Definition at line 28 of file class.ilAuthProviderOpenIdConnect.php.

◆ OIDC_AUTH_IDTOKEN

const ilAuthProviderOpenIdConnect::OIDC_AUTH_IDTOKEN = 'oidc_auth_idtoken'
private

Definition at line 25 of file class.ilAuthProviderOpenIdConnect.php.


The documentation for this class was generated from the following file: