diff --git a/composer.json b/composer.json index a55190d..c6e3e52 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ } ], "require": { - "phpseclib/phpseclib" : "2.0.1" + "phpseclib/phpseclib" : "3.0.42" }, "extra": { "installer-name": "IsekaiOIDC" diff --git a/includes/IsekaiOIDCAuth.php b/includes/IsekaiOIDCAuth.php index 130ad24..cb9d2ab 100644 --- a/includes/IsekaiOIDCAuth.php +++ b/includes/IsekaiOIDCAuth.php @@ -266,13 +266,11 @@ class IsekaiOIDCAuth extends AbstractPrimaryAuthenticationProvider { } if ( isset( $config['scope'] ) ) { $scope = $config['scope']; - if ( is_array( $scope ) ) { - foreach ( $scope as $s ) { - $oidc->addScope( $s ); - } - } else { - $oidc->addScope( $scope ); + if ( ! is_array( $scope ) ) { + $scope = [ $scope ]; } + + $oidc->addScope( $scope ); } if ( isset( $config['proxy'] ) ) { $oidc->setHttpProxy( $config['proxy'] ); diff --git a/includes/SpecialIsekaiOIDCCallback.php b/includes/SpecialIsekaiOIDCCallback.php index c735b40..87eff4d 100644 --- a/includes/SpecialIsekaiOIDCCallback.php +++ b/includes/SpecialIsekaiOIDCCallback.php @@ -35,7 +35,7 @@ class SpecialIsekaiOIDCCallback extends LoginSignupSpecialPage { } public function getDescription() { - return $this->msg( 'login' )->text(); + return $this->msg( 'login' ); } public function setHeaders() { diff --git a/lib/openid-connect-php/OpenIDConnectClient.php b/lib/openid-connect-php/OpenIDConnectClient.php index ac6bf18..8ddeb64 100644 --- a/lib/openid-connect-php/OpenIDConnectClient.php +++ b/lib/openid-connect-php/OpenIDConnectClient.php @@ -734,13 +734,11 @@ class OpenIDConnectClient /** * Start Here * @return void - * @throws OpenIDConnectClientException - * @throws Exception */ - private function requestAuthorization() { - - $auth_endpoint = $this->getProviderConfigValue('authorization_endpoint'); - $response_type = 'code'; + public function getAuthorizationUrl() + { + $auth_endpoint = $this->getProviderConfigValue("authorization_endpoint"); + $response_type = "code"; // Generate and store a nonce in the session // The nonce is an arbitrary value @@ -749,45 +747,29 @@ class OpenIDConnectClient // State essentially acts as a session key for OIDC $state = $this->setState($this->generateRandString()); - $auth_params = array_merge($this->authParams, [ + $auth_params = array_merge($this->authParams, array( 'response_type' => $response_type, 'redirect_uri' => $this->getRedirectURL(), 'client_id' => $this->clientID, 'nonce' => $nonce, 'state' => $state, 'scope' => 'openid' - ]); + )); // If the client has been registered with additional scopes - if (count($this->scopes) > 0) { - $auth_params = array_merge($auth_params, ['scope' => implode(' ', array_merge($this->scopes, ['openid']))]); + if (sizeof($this->scopes) > 0) { + $auth_params = array_merge($auth_params, array('scope' => implode(' ', $this->scopes))); } // If the client has been registered with additional response types - if (count($this->responseTypes) > 0) { - $auth_params = array_merge($auth_params, ['response_type' => implode(' ', $this->responseTypes)]); + if (sizeof($this->responseTypes) > 0) { + $auth_params = array_merge($auth_params, array('response_type' => implode(' ', $this->responseTypes))); } - // If the client supports Proof Key for Code Exchange (PKCE) - $codeChallengeMethod = $this->getCodeChallengeMethod(); - if (!empty($codeChallengeMethod) && in_array($codeChallengeMethod, $this->getProviderConfigValue('code_challenge_methods_supported', []), true)) { - $codeVerifier = bin2hex(random_bytes(64)); - $this->setCodeVerifier($codeVerifier); - if (!empty($this->pkceAlgs[$codeChallengeMethod])) { - $codeChallenge = rtrim(strtr(base64_encode(hash($this->pkceAlgs[$codeChallengeMethod], $codeVerifier, true)), '+/', '-_'), '='); - } else { - $codeChallenge = $codeVerifier; - } - $auth_params = array_merge($auth_params, [ - 'code_challenge' => $codeChallenge, - 'code_challenge_method' => $codeChallengeMethod - ]); - } + $auth_endpoint .= (strpos($auth_endpoint, '?') === false ? '?' : '&') . http_build_query($auth_params); - $auth_endpoint .= (strpos($auth_endpoint, '?') === false ? '?' : '&') . http_build_query($auth_params, '', '&', $this->encType); - - $this->commitSession(); - $this->redirect($auth_endpoint); + session_commit(); + return $auth_endpoint; } /** @@ -967,7 +949,7 @@ class OpenIDConnectClient } // Convert token params to string format - $post_params = http_build_query($post_data, null, '&', $this->encType); + $post_params = http_build_query($post_data, '', '&', $this->encType); return json_decode($this->fetchURL($token_endpoint, $post_params, $headers), false); }