Skip to content
Open
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
18 changes: 0 additions & 18 deletions phpstan-baseline-7.4.neon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 0 additions & 18 deletions phpstan-baseline-8.3.neon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ parameters:
paths:
- src/Toolkit/Core/Facade/*
- tests/unit/Toolkit/Core/Facade/*
- tests/fixtures/Toolkit/Http/OAuth2/OAuth2Client/OAuth2TestClient.php
-
identifier: salient.needless.coalesce
paths:
Expand Down
7 changes: 5 additions & 2 deletions src/Toolkit/Contract/Http/CredentialInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
interface CredentialInterface
{
/**
* Get the authentication scheme of the credential, e.g. "Bearer"
* Get the authentication scheme of the credential, e.g. "Basic", "Digest"
* or "Bearer"
*/
public function getAuthenticationScheme(): string;

/**
* Get the credential
* Get the credential, e.g. a Base64-encoded user ID/password pair, a
* comma-delimited list of authorization parameters or an OAuth 2.0 access
* token
*/
public function getCredential(): string;
}
42 changes: 42 additions & 0 deletions src/Toolkit/Http/GenericCredential.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php declare(strict_types=1);

namespace Salient\Http;

use Salient\Contract\Core\Immutable;
use Salient\Contract\Http\CredentialInterface;

/**
* @api
*/
class GenericCredential implements CredentialInterface, Immutable
{
private string $AuthenticationScheme;
private string $Credential;

/**
* @api
*/
public function __construct(
string $credential,
string $authenticationScheme
) {
$this->AuthenticationScheme = $authenticationScheme;
$this->Credential = $credential;
}

/**
* @inheritDoc
*/
public function getAuthenticationScheme(): string
{
return $this->AuthenticationScheme;
}

/**
* @inheritDoc
*/
public function getCredential(): string
{
return $this->Credential;
}
}
52 changes: 52 additions & 0 deletions src/Toolkit/Http/GenericToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php declare(strict_types=1);

namespace Salient\Http;

use Salient\Utility\Date;
use DateTimeImmutable;
use DateTimeInterface;
use InvalidArgumentException;

/**
* @api
*/
class GenericToken extends GenericCredential
{
private ?DateTimeImmutable $Expires;

/**
* @api
*
* @param DateTimeInterface|int|null $expires `null` if the token's lifetime
* is unknown or unlimited, otherwise a {@see DateTimeInterface} or Unix
* timestamp representing its expiration time.
*/
public function __construct(
string $token,
string $authenticationScheme,
$expires = null
) {
if (is_int($expires) && $expires < 0) {
throw new InvalidArgumentException(
sprintf('Invalid timestamp: %d', $expires),
);
}

$this->Expires = $expires instanceof DateTimeInterface
? Date::immutable($expires)
: ($expires !== null
? new DateTimeImmutable('@' . $expires)
: null);

parent::__construct($token, $authenticationScheme);
}

/**
* Get the expiration time of the token, or null if its lifetime is unknown
* or unlimited
*/
public function getExpires(): ?DateTimeImmutable
{
return $this->Expires;
}
}
82 changes: 0 additions & 82 deletions src/Toolkit/Http/OAuth2/AccessToken.php

This file was deleted.

47 changes: 47 additions & 0 deletions src/Toolkit/Http/OAuth2/HasGrantType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types=1);

namespace Salient\Http\OAuth2;

/**
* @api
*/
interface HasGrantType
{
/**
* Authorization code
*
* - \[RFC6749] Section 4.1 ("Authorization Code Grant")
* - \[OpenID.Core] Section 3.1 ("Authentication using the Authorization
* Code Flow")
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
*/
public const GRANT_AUTHORIZATION_CODE = 'authorization_code';

/**
* Resource owner password
*
* - \[RFC6749] Section 4.3 ("Resource Owner Password Credentials Grant")
*/
public const GRANT_PASSWORD = 'password';

/**
* Client credentials
*
* - \[RFC6749] Section 4.4 ("Client Credentials Grant")
*/
public const GRANT_CLIENT_CREDENTIALS = 'client_credentials';

/**
* Device code
*
* - \[RFC8628] ("OAuth 2.0 Device Authorization Grant")
*/
public const GRANT_DEVICE_CODE = 'urn:ietf:params:oauth:grant-type:device_code';

/**
* Refresh token
*
* - \[RFC6749] Section 6 ("Refreshing an Access Token")
*/
public const GRANT_REFRESH_TOKEN = 'refresh_token';
}
60 changes: 60 additions & 0 deletions src/Toolkit/Http/OAuth2/HasResponseType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php declare(strict_types=1);

namespace Salient\Http\OAuth2;

/**
* @api
*/
interface HasResponseType
{
/**
* Authorization code
*
* - \[RFC6749] Section 4.1 ("Authorization Code Grant")
* - \[OpenID.Core] Section 3.1 ("Authentication using the Authorization
* Code Flow")
*/
public const RESPONSE_CODE = 'code';

/**
* Token
*
* - \[RFC6749] Section 4.2 ("Implicit Grant")
*/
public const RESPONSE_TOKEN = 'token';

/**
* ID token
*
* - \[OpenID.Core] Section 3.2 ("Authentication using the Implicit Flow")
*/
public const RESPONSE_ID_TOKEN = 'id_token';

/**
* ID token + token
*
* - \[OpenID.Core] Section 3.2 ("Authentication using the Implicit Flow")
*/
public const RESPONSE_ID_TOKEN_TOKEN = 'id_token token';

/**
* Authorization code + ID token
*
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
*/
public const RESPONSE_CODE_ID_TOKEN = 'code id_token';

/**
* Authorization code + token
*
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
*/
public const RESPONSE_CODE_TOKEN = 'code token';

/**
* Authorization code + ID token + token
*
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
*/
public const RESPONSE_CODE_ID_TOKEN_TOKEN = 'code id_token token';
}
Loading
Loading