Skip to content
Closed
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"lint": "parallel-lint",
"phpstan": "phpstan analyse --memory-limit=512M",
"psalm": "psalm",
"phpcs": "phpcs --standard=PSR12"
"phpcs": "phpcs --standard=PSR12 --exclude=Generic.Files.LineLength"
}
}
4 changes: 2 additions & 2 deletions src/Config/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Constants

public static string $ORG_CLAIM = 'org';

public static function getValidIdentityClaims()
public static function getValidIdentityClaims(): array
{
return array_merge(
self::$VALID_IDENTITY_STRING_CLAIMS,
Expand All @@ -31,7 +31,7 @@ public static function getValidIdentityClaims()
);
}

public static function getValidScopes()
public static function getValidScopes(): array
{
return array_merge(
self::$VALID_IDENTITY_STRING_CLAIMS,
Expand Down
7 changes: 6 additions & 1 deletion src/Config/HelloConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class HelloConfig implements ConfigInterface
private string $logoutApiRoute;
private bool $sameSiteStrict;
private ?string $clientId;

/**
* Include encrypted cookie in auth response
* @var ?bool $cookieToken
*/
private ?bool $cookieToken = null;
private ?string $redirectURI;
private string $helloDomain;
Expand Down Expand Up @@ -52,7 +57,7 @@ public function __construct(
'loggedOut' => '/',
'error' => '/error',
],
?bool $cookieToken = null,
?bool $cookieToken = null, // include encrypted cookie in auth response
?bool $logDebug = null,
?array $error = null
) {
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/CallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class CallbackException extends Exception

public function __construct(
array $errorDetails,
$message = "Callback Exception",
$code = 0,
Throwable $previous = null
string $message = "Callback Exception",
int $code = 0,
?Throwable $previous = null
) {
$this->errorDetails = $errorDetails;
parent::__construct($message, $code, $previous);
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/SameSiteCallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class SameSiteCallbackException extends Exception
private array $errorDetails;

public function __construct(
$message = "Same Site Callback Exception",
$code = 0,
Throwable $previous = null
string $message = "Same Site Callback Exception",
int $code = 0,
?Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Handler/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use HelloCoop\Lib\TokenParser;
use Exception;
use HelloCoop\Utils\CurlWrapper;
use Throwable;

class Callback
{
Expand Down Expand Up @@ -260,13 +261,13 @@ public function handleCallback(): ?string
*
* @param array $error Error details including 'target_uri', 'error', and 'error_description'.
* @param string $errorMessage A message describing the error.
* @param \Throwable|null $previous Previous exception for chaining (optional).
* @param Throwable|null $previous Previous exception for chaining (optional).
*
* @return string The error page URL.
*
* @throws CallbackException If no error URI is provided.
*/
private function sendErrorPage(array $error, string $errorMessage, \Throwable $previous = null): string
private function sendErrorPage(array $error, string $errorMessage, ?Throwable $previous = null): string
{
$error_uri = $error['target_uri'] ?? $this->config->getRoutes()['error'] ?? null;
if ($error_uri) {
Expand Down
6 changes: 3 additions & 3 deletions src/HelloClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class HelloClient

public function __construct(
ConfigInterface $config,
HelloRequestInterface $helloRequest = null,
HelloResponseInterface $helloResponse = null,
PageRendererInterface $pageRenderer = null
?HelloRequestInterface $helloRequest = null,
?HelloResponseInterface $helloResponse = null,
?PageRendererInterface $pageRenderer = null
) {
$this->config = $config;
$this->helloRequest = $helloRequest ??= new HelloRequest();
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/PKCE.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class PKCE
{
const VERIFIER_LENGTH = 43;
public const VERIFIER_LENGTH = 43;

/** Generate cryptographically strong random string
* @param int $size The desired length of the string
Expand Down
22 changes: 14 additions & 8 deletions src/Type/AuthCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use InvalidArgumentException;

// Authentication cookie class, extending Claims
class AuthCookie extends Claims {
class AuthCookie extends Claims
{
/** @var int */
public $iat;

Expand All @@ -15,29 +16,33 @@ class AuthCookie extends Claims {
*/
public $extraProperties = [];

public function __construct(string $sub, int $iat) {
public function __construct(string $sub, int $iat)
{
parent::__construct($sub);
$this->iat = $iat;
}

/**
* Add an extra property.
*/
public function setExtraProperty(string $key, $value): void {
public function setExtraProperty(string $key, $value): void
{
$this->extraProperties[$key] = $value;
}

/**
* Get an extra property.
*/
public function getExtraProperty(string $key) {
public function getExtraProperty(string $key)
{
return $this->extraProperties[$key] ?? null;
}

/**
* Create an instance from an array of key-value pairs.
*/
public static function fromArray(array $data): self {
public static function fromArray(array $data): self
{
if (!isset($data['sub'], $data['iat'])) {
throw new InvalidArgumentException('Missing required keys "sub" or "iat".');
}
Expand All @@ -52,11 +57,12 @@ public static function fromArray(array $data): self {

return $instance;
}

/**
* Convert the instance to an array of key-value pairs.
*/
public function toArray(): array {
public function toArray(): array
{
return array_merge(['sub' => $this->sub, 'iat' => $this->iat], $this->extraProperties);
}
}
}
38 changes: 25 additions & 13 deletions src/Type/AuthUpdates.php
Original file line number Diff line number Diff line change
@@ -1,49 +1,61 @@
<?php

namespace HelloCoop\Type;
class AuthUpdates extends Claims implements \ArrayAccess {

class AuthUpdates extends Claims implements \ArrayAccess
{
private array $additionalProperties = [];

public function __construct(string $sub, int $iat, array $updates = []) {
parent::__construct($sub, $iat);
public function __construct(string $sub, array $updates = [])

Check warning on line 9 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L9

Added line #L9 was not covered by tests
{
parent::__construct($sub);

Check warning on line 11 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L11

Added line #L11 was not covered by tests
$this->additionalProperties = $updates;
}

// Magic methods for dynamic properties
public function __set(string $name, $value): void {
public function __set(string $name, $value): void

Check warning on line 16 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L16

Added line #L16 was not covered by tests
{
$this->additionalProperties[$name] = $value;
}

public function __get(string $name) {
public function __get(string $name)

Check warning on line 21 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L21

Added line #L21 was not covered by tests
{
return $this->additionalProperties[$name] ?? null;
}

public function __isset(string $name): bool {
public function __isset(string $name): bool

Check warning on line 26 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L26

Added line #L26 was not covered by tests
{
return isset($this->additionalProperties[$name]);
}

public function __unset(string $name): void {
public function __unset(string $name): void

Check warning on line 31 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L31

Added line #L31 was not covered by tests
{
unset($this->additionalProperties[$name]);
}

// ArrayAccess implementation
public function offsetExists($offset): bool {
public function offsetExists($offset): bool

Check warning on line 37 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L37

Added line #L37 was not covered by tests
{
return isset($this->additionalProperties[$offset]);
}

public function offsetGet($offset) {
public function offsetGet($offset): ?string

Check warning on line 42 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L42

Added line #L42 was not covered by tests
{
return $this->additionalProperties[$offset] ?? null;
}

public function offsetSet($offset, $value): void {
public function offsetSet($offset, $value): void

Check warning on line 47 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L47

Added line #L47 was not covered by tests
{
$this->additionalProperties[$offset] = $value;
}

public function offsetUnset($offset): void {
public function offsetUnset($offset): void

Check warning on line 52 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L52

Added line #L52 was not covered by tests
{
unset($this->additionalProperties[$offset]);
}

public function toArray(): array {
public function toArray(): array

Check warning on line 57 in src/Type/AuthUpdates.php

View check run for this annotation

Codecov / codecov/patch

src/Type/AuthUpdates.php#L57

Added line #L57 was not covered by tests
{
return array_merge(get_object_vars($this), $this->additionalProperties);
}
}
}
12 changes: 8 additions & 4 deletions src/Type/Claims.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
use HelloCoop\Type\Common\OptionalAccountClaimsTrait;
use HelloCoop\Type\Common\OptionalOrgClaimTrait;

class Claims {
use OptionalStringClaimsTrait, OptionalAccountClaimsTrait, OptionalOrgClaimTrait;
class Claims
{
use OptionalStringClaimsTrait;
use OptionalAccountClaimsTrait;
use OptionalOrgClaimTrait;

/** @var string */
public $sub;

public function __construct(string $sub) {
public function __construct(string $sub)
{
$this->sub = $sub;
}
}
}
5 changes: 3 additions & 2 deletions src/Type/Common/OptionalAccountClaimsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace HelloCoop\Type\Common;

trait OptionalAccountClaimsTrait {
trait OptionalAccountClaimsTrait
{
/**
* @var array<string, array{id: string, username: string}>
* An associative array of account claims (e.g., ['github' => ['id' => '123', 'username' => 'user']]).
*/
public $claims = [];
}
}
5 changes: 3 additions & 2 deletions src/Type/Common/OptionalOrgClaimTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace HelloCoop\Type\Common;

trait OptionalOrgClaimTrait {
trait OptionalOrgClaimTrait
{
/**
* @var array{id: string, domain: string}|null
* Optional organization claim.
*/
public $org;
}
}
24 changes: 13 additions & 11 deletions src/Type/Common/OptionalStringClaimsTrait.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

namespace HelloCoop\Type\Common;
trait OptionalStringClaimsTrait {
public $name;
public $nickname;
public $preferred_username;
public $given_name;
public $family_name;
public $email;
public $phone;
public $picture;
public $ethereum;
}

trait OptionalStringClaimsTrait
{
public string $name;
public string $nickname;
public string $preferred_username;
public string $given_name;
public string $family_name;
public string $email;
public string $phone;
public string $picture;
public string $ethereum;
}
13 changes: 8 additions & 5 deletions src/Type/OIDC.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@

use InvalidArgumentException;

class OIDC {
class OIDC
{
public string $codeVerifier;
public string $nonce;
public string $redirectUri;
public string $targetUri;

public function __construct(string $codeVerifier, string $nonce, string $redirectUri, string $targetUri) {
public function __construct(string $codeVerifier, string $nonce, string $redirectUri, string $targetUri)
{
$this->codeVerifier = $codeVerifier;
$this->nonce = $nonce;
$this->redirectUri = $redirectUri;
$this->targetUri = $targetUri;
}

public static function fromArray(array $data): self {
public static function fromArray(array $data): self
{
if (!isset($data['code_verifier'])) {
throw new InvalidArgumentException('Missing code_verifier');
}
Expand All @@ -42,7 +45,8 @@ public static function fromArray(array $data): self {
);
}

public function toArray(): array {
public function toArray(): array
{
return [
'code_verifier' => $this->codeVerifier,
'nonce' => $this->nonce,
Expand All @@ -51,4 +55,3 @@ public function toArray(): array {
];
}
}

2 changes: 1 addition & 1 deletion tests/Config/HelloConfigBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class HelloConfigBuilderTest extends TestCase
{
public function testHelloConfigBuilderBuildsConfigCorrectly()
public function testHelloConfigBuilderBuildsConfigCorrectly(): void
{
// Arrange: Create the builder and set values
$builder = new HelloConfigBuilder();
Expand Down
Loading
Loading