23
23
class ilAuthProviderOpenIdConnect extends ilAuthProvider
24
24
{
25
25
private ilOpenIdConnectSettings $ settings ;
26
+ /** @var array $body */
27
+ private $ body ;
28
+ private ilLogger $ logger ;
26
29
27
30
public function __construct (ilAuthCredentials $ credentials )
28
31
{
32
+ global $ DIC ;
29
33
parent ::__construct ($ credentials );
34
+
35
+ $ this ->logger = $ DIC ->logger ()->auth ();
30
36
$ this ->settings = ilOpenIdConnectSettings::getInstance ();
37
+ $ this ->body = $ DIC ->http ()->request ()->getParsedBody ();
31
38
}
32
39
33
40
public function handleLogout () : void
@@ -37,7 +44,7 @@ public function handleLogout() : void
37
44
}
38
45
39
46
$ auth_token = ilSession::get ('oidc_auth_token ' );
40
- $ this ->getLogger () ->debug ('Using token: ' . $ auth_token );
47
+ $ this ->logger ->debug ('Using token: ' . $ auth_token );
41
48
42
49
if (isset ($ auth_token ) && $ auth_token !== '' ) {
43
50
ilSession::set ('oidc_auth_token ' , '' );
@@ -65,7 +72,7 @@ public function doAuthentication(ilAuthStatus $status) : bool
65
72
$ oidc ->setHttpProxy ($ host );
66
73
}
67
74
68
- $ this ->getLogger () ->debug (
75
+ $ this ->logger ->debug (
69
76
'Redirect url is: ' .
70
77
$ oidc ->getRedirectURL ()
71
78
);
@@ -79,32 +86,31 @@ public function doAuthentication(ilAuthStatus $status) : bool
79
86
80
87
$ oidc ->addScope ($ this ->settings ->getAllScopes ());
81
88
$ oidc ->addAuthParam (['response_mode ' => 'form_post ' ]);
82
- switch ($ this ->settings ->getLoginPromptType ()) {
83
- case ilOpenIdConnectSettings::LOGIN_ENFORCE :
84
- $ oidc ->addAuthParam (['prompt ' => 'login ' ]);
85
- break ;
89
+ if ($ this ->settings ->getLoginPromptType () === ilOpenIdConnectSettings::LOGIN_ENFORCE ) {
90
+ $ oidc ->addAuthParam (['prompt ' => 'login ' ]);
86
91
}
87
92
$ oidc ->setAllowImplicitFlow (true );
88
93
89
94
$ oidc ->authenticate ();
90
95
// user is authenticated, otherwise redirected to authorization endpoint or exception
91
- $ this ->getLogger () ->dump ($ _REQUEST , ilLogLevel::DEBUG );
96
+ $ this ->logger ->dump ($ this -> body , ilLogLevel::DEBUG );
92
97
93
98
$ claims = $ oidc ->getVerifiedClaims (null );
94
- $ this ->getLogger () ->dump ($ claims , ilLogLevel::DEBUG );
99
+ $ this ->logger ->dump ($ claims , ilLogLevel::DEBUG );
95
100
$ status = $ this ->handleUpdate ($ status , $ claims );
96
101
97
102
// @todo : provide a general solution for all authentication methods
98
- $ _GET ['target ' ] = ( string ) $ this ->getCredentials ()->getRedirectionTarget ();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
103
+ // $_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
99
104
100
- if ($ this ->settings ->getLogoutScope () === ilOpenIdConnectSettings::LOGOUT_SCOPE_GLOBAL ) {
101
- $ token = $ oidc ->requestClientCredentialsToken ();
102
- ilSession::set ('oidc_auth_token ' , $ token ->access_token );
103
- }
105
+ //TODO fix this. There is a PR and it is broken in 7 as well
106
+ //if ($this->settings->getLogoutScope() === ilOpenIdConnectSettings::LOGOUT_SCOPE_GLOBAL) {
107
+ //$token = $oidc->requestClientCredentialsToken();
108
+ //ilSession::set('oidc_auth_token', $token->access_token);
109
+ //}
104
110
return true ;
105
111
} catch (Exception $ e ) {
106
- $ this ->getLogger () ->warning ($ e ->getMessage ());
107
- $ this ->getLogger () ->warning ($ e ->getCode ());
112
+ $ this ->logger ->warning ($ e ->getMessage ());
113
+ $ this ->logger ->warning (( string ) $ e ->getCode ());
108
114
$ status ->setStatus (ilAuthStatus::STATUS_AUTHENTICATION_FAILED );
109
115
$ status ->setTranslatedReason ($ e ->getMessage ());
110
116
return false ;
@@ -120,17 +126,17 @@ public function doAuthentication(ilAuthStatus $status) : bool
120
126
private function handleUpdate (ilAuthStatus $ status , $ user_info ) : ilAuthStatus
121
127
{
122
128
if (!is_object ($ user_info )) {
123
- $ this ->getLogger () ->error ('Received invalid user credentials: ' );
124
- $ this ->getLogger () ->dump ($ user_info , ilLogLevel::ERROR );
129
+ $ this ->logger ->error ('Received invalid user credentials: ' );
130
+ $ this ->logger ->dump ($ user_info , ilLogLevel::ERROR );
125
131
$ status ->setStatus (ilAuthStatus::STATUS_AUTHENTICATION_FAILED );
126
132
$ status ->setReason ('err_wrong_login ' );
127
133
return $ status ;
128
134
}
129
135
130
136
$ uid_field = $ this ->settings ->getUidField ();
131
- $ ext_account = $ user_info ->$ uid_field ;
137
+ $ ext_account = $ user_info ->{ $ uid_field} ;
132
138
133
- $ this ->getLogger () ->debug ('Authenticated external account: ' . $ ext_account );
139
+ $ this ->logger ->debug ('Authenticated external account: ' . $ ext_account );
134
140
135
141
136
142
$ int_account = ilObjUser::_checkExternalAuthAccount (
@@ -154,7 +160,7 @@ private function handleUpdate(ilAuthStatus $status, $user_info) : ilAuthStatus
154
160
$ status ->setAuthenticatedUserId ($ user_id );
155
161
$ status ->setStatus (ilAuthStatus::STATUS_AUTHENTICATED );
156
162
157
- $ _GET ['target ' ] = ( string ) $ this ->getCredentials ()->getRedirectionTarget ();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
163
+ // $_GET['target'] = $this->getCredentials()->getRedirectionTarget();// TODO PHP8-REVIEW Please eliminate this. Mutating the request is not allowed and will not work in ILIAS 8.
158
164
} catch (ilOpenIdConnectSyncForbiddenException $ e ) {
159
165
$ status ->setStatus (ilAuthStatus::STATUS_AUTHENTICATION_FAILED );
160
166
$ status ->setReason ('err_wrong_login ' );
0 commit comments