ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilAuthProviderOpenIdConnect Class Reference

Class ilAuthProviderOpenIdConnect. More...

+ 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)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
- Public Member Functions inherited from ilAuthProviderInterface
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 

Private Member Functions

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

Private Attributes

const OIDC_AUTH_IDTOKEN = "oidc_auth_idtoken"
 
ilOpenIdConnectSettings $settings
 
ilLogger $logger
 
ilLanguage $lng
 

Additional Inherited Members

- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, string $a_reason)
 Handle failed authentication. More...
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderOpenIdConnect::__construct ( ilAuthCredentials  $credentials)

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

References $DIC, ILIAS\MetaData\Repository\Validation\Data\__construct(), ilOpenIdConnectSettings\getInstance(), ILIAS\Repository\lng(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

36  {
37  global $DIC;
38  parent::__construct($credentials);
39 
40  $this->logger = $DIC->logger()->auth();
42  $this->lng = $DIC->language();
43  $this->lng->loadLanguageModule('auth');
44  }
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
+ Here is the call graph for this function:

Member Function Documentation

◆ doAuthentication()

ilAuthProviderOpenIdConnect::doAuthentication ( ilAuthStatus  $status)

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

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.

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

◆ handleLogout()

ilAuthProviderOpenIdConnect::handleLogout ( )

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

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

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  }
68  }
static get(string $a_var)
static logoutUrl(array $parameters=[])
Return the logout URL with a valid CSRF token.
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ handleUpdate()

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

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

References Vendor\Package\$e, ilAuthProvider\$status, ilAuthProvider\$user_id, ilObjUser\_checkExternalAuthAccount(), ilOpenIdConnectUserSync\AUTH_MODE, ilAuthUtils\AUTH_OPENID_CONNECT, ilLogLevel\ERROR, ILIAS\Repository\logger(), ilSession\set(), ilAuthStatus\setReason(), ilAuthStatus\setStatus(), ILIAS\Repository\settings(), ilAuthStatus\STATUS_AUTHENTICATED, and ilAuthStatus\STATUS_AUTHENTICATION_FAILED.

Referenced by doAuthentication().

125  : ilAuthStatus
126  {
127  if (!is_object($user_info)) {
128  $this->logger->error('Received invalid user credentials: ');
129  $this->logger->dump($user_info, ilLogLevel::ERROR);
131  $status->setReason('err_wrong_login');
132  return $status;
133  }
134 
135  $uid_field = $this->settings->getUidField();
136  $ext_account = $user_info->{$uid_field} ?? '';
137 
138  if (!is_string($ext_account) || $ext_account === '') {
139  $this->logger->error('Could not determine valid external account, value is empty or not a string.');
140  $this->logger->dump($user_info, ilLogLevel::ERROR);
142  $status->setReason('err_wrong_login');
143  return $status;
144  }
145 
146  $this->logger->debug('Authenticated external account: ' . $ext_account);
147 
150  $ext_account
151  );
152 
153  try {
154  $sync = new ilOpenIdConnectUserSync($this->settings, $user_info);
155  $sync->setExternalAccount($ext_account);
156  $sync->setInternalAccount((string) $int_account);
157  $sync->updateUser();
158 
159  $user_id = $sync->getUserId();
160  ilSession::set('used_external_auth_mode', ilAuthUtils::AUTH_OPENID_CONNECT);
163 
164  //$_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
167  $status->setReason('err_wrong_login');
168  }
169 
170  return $status;
171  }
const AUTH_OPENID_CONNECT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const STATUS_AUTHENTICATION_FAILED
static _checkExternalAuthAccount(string $a_auth, string $a_account, bool $tryFallback=true)
check whether external account and authentication method matches with a user
setStatus(int $a_status)
Set auth status.
setReason(string $a_reason)
Set reason.
setAuthenticatedUserId(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initClient()

ilAuthProviderOpenIdConnect::initClient ( )
private

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

References ILIAS\Repository\settings().

Referenced by doAuthentication(), and handleLogout().

173  : OpenIDConnectClient
174  {
175  $oidc = new OpenIDConnectClient(
176  $this->settings->getProvider(),
177  $this->settings->getClientId(),
178  $this->settings->getSecret()
179  );
180 
181  return $oidc;
182  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $lng

ilLanguage ilAuthProviderOpenIdConnect::$lng
private

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

◆ $logger

ilLogger ilAuthProviderOpenIdConnect::$logger
private

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

◆ $settings

ilOpenIdConnectSettings ilAuthProviderOpenIdConnect::$settings
private

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

◆ OIDC_AUTH_IDTOKEN

const ilAuthProviderOpenIdConnect::OIDC_AUTH_IDTOKEN = "oidc_auth_idtoken"
private

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


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