Skip to content
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
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
],
"type": "library",
"require": {
"php": ">=7.4 <=8.4.1"
"php": ">=7.4 <=8.4.1",
"ext-json": "*",
"ext-openssl": "*",
"ext-curl": "*"
},
"license": "MIT",
"autoload": {
Expand Down Expand Up @@ -39,7 +42,8 @@
"phpunit/phpunit": "^9.6",
"slevomat/coding-standard": "^8.4",
"squizlabs/php_codesniffer": "^3.11",
"vimeo/psalm": "^4.9"
"vimeo/psalm": "^4.9",
"friendsofphp/php-cs-fixer": "^3.65"
},
"scripts": {
"analyze": [
Expand Down
5 changes: 5 additions & 0 deletions src/Config/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ interface ConfigInterface
{
public function getProduction(): bool;
public function getSameSiteStrict(): ?bool;
/** @return array<string, int|string>|null */
public function getError(): ?array;
/** @return array<string, string>|null */
public function getScope(): ?array;
/** @return array<string>|null */
public function getProviderHint(): ?array;
/** @return array<string, string> */
public function getRoutes(): array;
/** @return array<string, string> */
public function getCookies(): array;
public function getLoginSync(): ?callable;
public function getLogoutSync(): ?callable;
Expand Down
19 changes: 16 additions & 3 deletions src/Config/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@ class Constants
public static string $PRODUCTION_WALLET = 'https://wallet.hello.coop';
public static string $DEFAULT_PATH = '/authorize';
public static string $HELLO_API_ROUTE = '/api/hellocoop';
/** @var array<string> */
public static array $DEFAULT_SCOPE = ['openid', 'name', 'email', 'picture'];
public static string $DEFAULT_RESPONSE_TYPE = 'code';
public static string $DEFAULT_RESPONSE_MODE = 'query';

/** @var array<string> */
public static array $VALID_IDENTITY_STRING_CLAIMS = [
'name', 'nickname', 'preferred_username', 'given_name', 'family_name',
'email', 'phone', 'picture', 'ethereum',
];

/**
* @var array<string>
*/
public static array $VALID_IDENTITY_ACCOUNT_CLAIMS = [
'discord', 'twitter', 'github', 'gitlab'
];

public static string $ORG_CLAIM = 'org';

public static function getValidIdentityClaims()
/**
* @return array<string>
*/
public static function getValidIdentityClaims(): array
{
return array_merge(
self::$VALID_IDENTITY_STRING_CLAIMS,
Expand All @@ -31,7 +39,10 @@ public static function getValidIdentityClaims()
);
}

public static function getValidScopes()
/**
* @return array<string>
*/
public static function getValidScopes(): array
{
return array_merge(
self::$VALID_IDENTITY_STRING_CLAIMS,
Expand All @@ -40,9 +51,11 @@ public static function getValidScopes()
);
}

/** @var array<string> */
public static array $VALID_RESPONSE_TYPE = ['id_token', 'code'];
/** @var array<string> */
public static array $VALID_RESPONSE_MODE = ['fragment', 'query', 'form_post'];

/** @var array<string> */
public static array $VALID_PROVIDER_HINT = [
'apple', 'discord', 'facebook', 'github', 'gitlab', 'google',
'twitch', 'twitter', 'tumblr', 'mastodon', 'microsoft', 'line',
Expand Down
45 changes: 45 additions & 0 deletions src/Config/HelloConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,45 @@ class HelloConfig implements ConfigInterface
private string $host;
private ?string $secret = null;
private ?bool $logDebug = null;
/** @var array<string, int|string>|null */
private ?array $error = null;
/** @var array<string> */
private array $scope;
/** @var array<string> */
private array $providerHint;
/** @var array<string, string> */
private array $routes;
/** @var array<string, string> */
private array $cookies;
/** @var callable|null */
private $loginSync;
/** @var callable|null */
private $logoutSync;
private bool $production;

/**
* @param string $apiRoute
* @param string $authApiRoute
* @param string $loginApiRoute
* @param string $logoutApiRoute
* @param bool $sameSiteStrict
* @param string|null $clientId
* @param string|null $redirectURI
* @param string $host
* @param string|null $secret
* @param callable|null $loginSync
* @param callable|null $logoutSync
* @param array<string, string> $cookies
* @param bool $production
* @param string $helloDomain
* @param string|null $helloWallet
* @param array<string> $scope
* @param array<string> $providerHint
* @param array<string, string> $routes
* @param bool|null $cookieToken
* @param bool|null $logDebug
* @param array<string, int|string>|null $error
*/
public function __construct(
string $apiRoute,
string $authApiRoute,
Expand Down Expand Up @@ -89,26 +119,41 @@ public function getSameSiteStrict(): ?bool
return $this->sameSiteStrict;
}

/**
* @return array<string, int|string>|null
*/
public function getError(): ?array
{
return $this->error;
}

/**
* @return array<string>|null
*/
public function getScope(): ?array
{
return $this->scope;
}

/**
* @return array<string>|null
*/
public function getProviderHint(): ?array
{
return $this->providerHint;
}

/**
* @return array<string, string>
*/
public function getRoutes(): array
{
return $this->routes;
}

/**
* @return array<string, string>
*/
public function getCookies(): array
{
return $this->cookies;
Expand Down
30 changes: 30 additions & 0 deletions src/Config/HelloConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@ class HelloConfigBuilder
private ?string $redirectURI = null;
private string $host = '';
private ?string $secret = null;
/** @var array<string, string> */
private array $cookies = [
'authName' => 'hellocoop_auth',
'oidcName' => 'hellocoop_oidc',
];
private bool $production = true;
private string $helloDomain = 'hello.coop';
private ?string $helloWallet = null;
/** @var array<string> */
private array $scope = ['openid', 'name', 'email', 'picture'];
/** @var array<string> */
private array $providerHint = ['github'];
/** @var array<string, string> */
private array $routes = [
'loggedIn' => '/',
'loggedOut' => '/',
'error' => '/error',
];
/** @var callable|null */
private $loginSync = null;
/** @var callable|null */
private $logoutSync = null;
private ?bool $cookieToken = null;
private ?bool $logDebug = null;
/** @var array<string, int|string>|null */
private ?array $error = null;

public function setApiRoute(string $apiRoute): self
Expand Down Expand Up @@ -87,6 +94,9 @@ public function setSecret(?string $secret): self
return $this;
}

/**
* @param array<string, string> $cookies
*/
public function setCookies(array $cookies): self
{
$this->cookies = $cookies;
Expand All @@ -111,30 +121,47 @@ public function setHelloWallet(?string $helloWallet): self
return $this;
}

/**
* @param array<string> $scope
*/
public function setScope(array $scope): self
{
$this->scope = $scope;
return $this;
}

/**
* @param array<string> $providerHint
*/
public function setProviderHint(array $providerHint): self
{
$this->providerHint = $providerHint;
return $this;
}

/**
* @param array<string, string> $routes
*/
public function setRoutes(array $routes): self
{
$this->routes = $routes;
return $this;
}

/**
* @param callable|null $loginSync
* @return HelloConfigBuilder
*/
public function setLoginSync(?callable $loginSync): self
{
$this->loginSync = $loginSync;
return $this;
}

/**
* @param callable|null $logoutSync
* @return HelloConfigBuilder
*/
public function setLogoutSync(?callable $logoutSync): self
{
$this->logoutSync = $logoutSync;
Expand All @@ -153,6 +180,9 @@ public function setLogDebug(?bool $logDebug): self
return $this;
}

/**
* @param array<string, int|string>|null $error
*/
public function setError(?array $error): self
{
$this->error = $error;
Expand Down
10 changes: 10 additions & 0 deletions src/Exception/CallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

class CallbackException extends Exception
{
/** @var array<string, int|string> */
private array $errorDetails;

/**
* @param array<string, int|string> $errorDetails
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(
array $errorDetails,
$message = "Callback Exception",
Expand All @@ -19,6 +26,9 @@ public function __construct(
parent::__construct($message, $code, $previous);
}

/**
* @return array<string, int|string>
*/
public function getErrorDetails(): array
{
return $this->errorDetails;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/CryptoFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

class CryptoFailedException extends Exception
{
/** @var string */
protected $message = 'Crypto failed. There was an error encrypting the data.';
}
1 change: 1 addition & 0 deletions src/Exception/DecryptionFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

class DecryptionFailedException extends Exception
{
/** @var string */
protected $message = 'Decryption failed. The data may be corrupted or the wrong key was used.';
}
1 change: 1 addition & 0 deletions src/Exception/InvalidSecretException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

class InvalidSecretException extends Exception
{
/** @var string */
protected $message = 'Invalid secret key. Must be a 64-character hexadecimal string.';
}
2 changes: 2 additions & 0 deletions src/Exception/NotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

class NotImplementedException extends BadMethodCallException
{
/** @var string */
protected $message = 'Not Implemented.';
}
7 changes: 5 additions & 2 deletions src/Exception/SameSiteCallbackException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

class SameSiteCallbackException extends Exception
{
private array $errorDetails;

/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
public function __construct(
$message = "Same Site Callback Exception",
$code = 0,
Expand Down
3 changes: 3 additions & 0 deletions src/Handler/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Auth
private HelloRequestInterface $helloRequest;
private ConfigInterface $config;
private ?AuthLib $authLib = null;

public function __construct(
HelloRequestInterface $helloRequest,
HelloResponseInterface $helloResponse,
Expand All @@ -38,6 +39,7 @@ public function handleAuth(): ?AuthType
{
return $this->getAuthLib()->getAuthfromCookies();
}

public function updateAuth(AuthUpdates $authUpdates): ?AuthType
{
$auth = $this->getAuthLib()->getAuthfromCookies();
Expand All @@ -48,6 +50,7 @@ public function updateAuth(AuthUpdates $authUpdates): ?AuthType
$updatedAuth = array_merge($auth->toArray(), $authUpdates->toArray());
return AuthType::fromArray($updatedAuth);
}

public function clearAuth(): void
{
$this->getAuthLib()->clearAuthCookie();
Expand Down
Loading
Loading