Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: method signatures after 1.0 release #427

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/OpenIDConnectClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright MITRE 2020
*
* OpenIDConnectClient for PHP5
* OpenIDConnectClient for PHP7+
* Author: Michael Jett <mjett@mitre.org>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand All @@ -25,7 +25,6 @@

use Error;
use Exception;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Crypt\RSA;
use phpseclib3\Math\BigInteger;
use stdClass;
Expand Down Expand Up @@ -380,7 +379,7 @@ public function authenticate(): bool
$accessToken = $_REQUEST['access_token'] ?? null;

// Do an OpenID Connect session check
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
if (!isset($_REQUEST['state']) || ($_REQUEST['state'] !== $this->getState())) {
throw new OpenIDConnectClientException('Unable to determine state');
}

Expand Down Expand Up @@ -691,7 +690,7 @@ public function getRedirectURL(): string
if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
$port = (int)$_SERVER['HTTP_X_FORWARDED_PORT'];
} elseif (isset($_SERVER['SERVER_PORT'])) {
$port = (int)$_SERVER['SERVER_PORT'];
$port = $_SERVER['SERVER_PORT'];
} elseif ($protocol === 'https') {
$port = 443;
} else {
Expand Down Expand Up @@ -1221,10 +1220,9 @@ protected function urlEncode(string $str): string
/**
* @param string $jwt encoded JWT
* @param int $section the section we would like to decode
* @return object
* @return object|null
*/
protected function decodeJWT(string $jwt, int $section = 0): stdClass {

protected function decodeJWT(string $jwt, int $section = 0) {
$parts = explode('.', $jwt);
return json_decode(base64url_decode($parts[$section]), false);
}
Expand Down Expand Up @@ -1688,7 +1686,10 @@ public function revokeToken(string $token, string $token_type_hint = '', string
return json_decode($this->fetchURL($revocation_endpoint, $post_params, $headers), false);
}

public function getClientName(): string
/**
* @return string|null
*/
public function getClientName()
{
return $this->clientName;
}
Expand All @@ -1698,14 +1699,14 @@ public function setClientName(string $clientName) {
}

/**
* @return string
* @return string|null
*/
public function getClientID() {
return $this->clientID;
}

/**
* @return string
* @return string|null
*/
public function getClientSecret() {
return $this->clientSecret;
Expand All @@ -1720,17 +1721,26 @@ public function setAccessToken(string $accessToken) {
$this->accessToken = $accessToken;
}

public function getAccessToken(): string
/**
* @return string|null
*/
public function getAccessToken()
{
return $this->accessToken;
}

public function getRefreshToken(): string
/**
* @return string|null
*/
public function getRefreshToken()
{
return $this->refreshToken;
}

public function getIdToken(): string
/**
* @return string|null
*/
public function getIdToken()
{
return $this->idToken;
}
Expand Down
35 changes: 32 additions & 3 deletions tests/OpenIDConnectClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,38 @@

class OpenIDConnectClientTest extends TestCase
{
/**
* @return void
*/
public function testJWTDecode()
{
$client = new OpenIDConnectClient();
$client->setAccessToken('');
$header = $client->getAccessTokenHeader();
self::assertEquals('', $header);
}

public function testGetNull()
{
$client = new OpenIDConnectClient();
self::assertNull($client->getAccessToken());
self::assertNull($client->getRefreshToken());
self::assertNull($client->getIdToken());
self::assertNull($client->getClientName());
self::assertNull($client->getClientID());
self::assertNull($client->getClientSecret());
self::assertNull($client->getCertPath());
}

public function testResponseTypes()
{
$client = new OpenIDConnectClient();
self::assertEquals([], $client->getResponseTypes());

$client->setResponseTypes('foo');
self::assertEquals(['foo'], $client->getResponseTypes());

$client->setResponseTypes(['bar', 'ipsum']);
self::assertEquals(['foo', 'bar', 'ipsum'], $client->getResponseTypes());
}

public function testGetRedirectURL()
{
$client = new OpenIDConnectClient();
Expand Down