ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 
 $body
 
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 36 of file class.ilAuthProviderOpenIdConnect.php.

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

37  {
38  global $DIC;
39  parent::__construct($credentials);
40 
41  $this->logger = $DIC->logger()->auth();
43  $this->body = $DIC->http()->request()->getParsedBody();
44  $this->lng = $DIC->language();
45  $this->lng->loadLanguageModule('auth');
46  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ doAuthentication()

ilAuthProviderOpenIdConnect::doAuthentication ( ilAuthStatus  $status)

Definition at line 72 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.

72  : bool
73  {
74  try {
75  $oidc = $this->initClient();
76  $oidc->setRedirectURL(ILIAS_HTTP_PATH . '/openidconnect.php');
77 
79  if ($proxy->isActive()) {
80  $host = $proxy->getHost();
81  $port = $proxy->getPort();
82  if ($port) {
83  $host .= ":" . $port;
84  }
85  $oidc->setHttpProxy($host);
86  }
87 
88  $this->logger->debug(
89  'Redirect url is: ' .
90  $oidc->getRedirectURL()
91  );
92 
93  $oidc->addScope($this->settings->getAllScopes());
94  if ($this->settings->getLoginPromptType() === ilOpenIdConnectSettings::LOGIN_ENFORCE) {
95  $oidc->addAuthParam(['prompt' => 'login']);
96  }
97 
98  $oidc->authenticate();
99  // user is authenticated, otherwise redirected to authorization endpoint or exception
100  $this->logger->dump($this->body, ilLogLevel::DEBUG);
101 
102  $claims = $oidc->getVerifiedClaims();
103  $this->logger->dump($claims, ilLogLevel::DEBUG);
104  $status = $this->handleUpdate($status, $claims);
105 
106  // @todo : provide a general solution for all authentication methods
107  //$_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
108 
109  if ($this->settings->getLogoutScope() === ilOpenIdConnectSettings::LOGOUT_SCOPE_GLOBAL) {
110  ilSession::set(self::OIDC_AUTH_IDTOKEN, $oidc->getIdToken());
111  }
112  return true;
113  } catch (Exception $e) {
114  $this->logger->warning($e->getMessage());
115  $this->logger->warning((string) $e->getCode());
117  $status->setTranslatedReason($this->lng->txt("auth_oidc_failed"));
118  return false;
119  }
120  }
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 48 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().

48  : void
49  {
50  if ($this->settings->getLogoutScope() === ilOpenIdConnectSettings::LOGOUT_SCOPE_LOCAL) {
51  return;
52  }
53 
54  $id_token = ilSession::get(self::OIDC_AUTH_IDTOKEN);
55  $this->logger->debug('Logging out with token: ' . $id_token);
56 
57  if (isset($id_token) && $id_token !== '') {
58  ilSession::set(self::OIDC_AUTH_IDTOKEN, '');
59  $oidc = $this->initClient();
60  try {
61  $oidc->signOut(
62  $id_token,
63  ILIAS_HTTP_PATH . '/' . ilStartUpGUI::logoutUrl()
64  );
65  } catch (\Jumbojett\OpenIDConnectClientException $e) {
66  $this->logger->warning("Logging out of OIDC provider failed with: " . $e->getMessage());
67  }
68 
69  }
70  }
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 128 of file class.ilAuthProviderOpenIdConnect.php.

References Vendor\Package\$e, ilAuthProvider\$status, ilAuthProvider\$user_id, ilObjUser\_checkExternalAuthAccount(), ilOpenIdConnectUserSync\AUTH_MODE, 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().

128  : ilAuthStatus
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('err_wrong_login');
135  return $status;
136  }
137 
138  $uid_field = $this->settings->getUidField();
139  $ext_account = $user_info->{$uid_field};
140 
141  $this->logger->debug('Authenticated external account: ' . $ext_account);
142 
143 
146  $ext_account
147  );
148 
149  try {
150  $sync = new ilOpenIdConnectUserSync($this->settings, $user_info);
151  if (!is_string($ext_account)) {
153  $status->setReason('err_wrong_login');
154  return $status;
155  }
156  $sync->setExternalAccount($ext_account);
157  $sync->setInternalAccount((string) $int_account);
158  $sync->updateUser();
159 
160  $user_id = $sync->getUserId();
161  ilSession::set('used_external_auth', true);
164 
165  //$_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
168  $status->setReason('err_wrong_login');
169  }
170 
171  return $status;
172  }
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)
Auth status implementation.
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 174 of file class.ilAuthProviderOpenIdConnect.php.

References ILIAS\Repository\settings().

Referenced by doAuthentication(), and handleLogout().

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

Field Documentation

◆ $body

ilAuthProviderOpenIdConnect::$body
private

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

◆ $lng

ilLanguage ilAuthProviderOpenIdConnect::$lng
private

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

◆ $logger

ilLogger ilAuthProviderOpenIdConnect::$logger
private

Definition at line 33 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: