Skip to content

Commit d65a3bd

Browse files
committed
Merge branch 'review-http'
2 parents 9042a5f + b7f6a33 commit d65a3bd

File tree

17 files changed

+368
-325
lines changed

17 files changed

+368
-325
lines changed

phpstan-baseline-7.4.neon

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline-8.3.neon

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ parameters:
4040
paths:
4141
- src/Toolkit/Core/Facade/*
4242
- tests/unit/Toolkit/Core/Facade/*
43+
- tests/fixtures/Toolkit/Http/OAuth2/OAuth2Client/OAuth2TestClient.php
4344
-
4445
identifier: salient.needless.coalesce
4546
paths:

src/Toolkit/Contract/Http/CredentialInterface.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
interface CredentialInterface
99
{
1010
/**
11-
* Get the authentication scheme of the credential, e.g. "Bearer"
11+
* Get the authentication scheme of the credential, e.g. "Basic", "Digest"
12+
* or "Bearer"
1213
*/
1314
public function getAuthenticationScheme(): string;
1415

1516
/**
16-
* Get the credential
17+
* Get the credential, e.g. a Base64-encoded user ID/password pair, a
18+
* comma-delimited list of authorization parameters or an OAuth 2.0 access
19+
* token
1720
*/
1821
public function getCredential(): string;
1922
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http;
4+
5+
use Salient\Contract\Core\Immutable;
6+
use Salient\Contract\Http\CredentialInterface;
7+
8+
/**
9+
* @api
10+
*/
11+
class GenericCredential implements CredentialInterface, Immutable
12+
{
13+
private string $AuthenticationScheme;
14+
private string $Credential;
15+
16+
/**
17+
* @api
18+
*/
19+
public function __construct(
20+
string $credential,
21+
string $authenticationScheme
22+
) {
23+
$this->AuthenticationScheme = $authenticationScheme;
24+
$this->Credential = $credential;
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function getAuthenticationScheme(): string
31+
{
32+
return $this->AuthenticationScheme;
33+
}
34+
35+
/**
36+
* @inheritDoc
37+
*/
38+
public function getCredential(): string
39+
{
40+
return $this->Credential;
41+
}
42+
}

src/Toolkit/Http/GenericToken.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http;
4+
5+
use Salient\Utility\Date;
6+
use DateTimeImmutable;
7+
use DateTimeInterface;
8+
use InvalidArgumentException;
9+
10+
/**
11+
* @api
12+
*/
13+
class GenericToken extends GenericCredential
14+
{
15+
private ?DateTimeImmutable $Expires;
16+
17+
/**
18+
* @api
19+
*
20+
* @param DateTimeInterface|int|null $expires `null` if the token's lifetime
21+
* is unknown or unlimited, otherwise a {@see DateTimeInterface} or Unix
22+
* timestamp representing its expiration time.
23+
*/
24+
public function __construct(
25+
string $token,
26+
string $authenticationScheme,
27+
$expires = null
28+
) {
29+
if (is_int($expires) && $expires < 0) {
30+
throw new InvalidArgumentException(
31+
sprintf('Invalid timestamp: %d', $expires),
32+
);
33+
}
34+
35+
$this->Expires = $expires instanceof DateTimeInterface
36+
? Date::immutable($expires)
37+
: ($expires !== null
38+
? new DateTimeImmutable('@' . $expires)
39+
: null);
40+
41+
parent::__construct($token, $authenticationScheme);
42+
}
43+
44+
/**
45+
* Get the expiration time of the token, or null if its lifetime is unknown
46+
* or unlimited
47+
*/
48+
public function getExpires(): ?DateTimeImmutable
49+
{
50+
return $this->Expires;
51+
}
52+
}

src/Toolkit/Http/OAuth2/AccessToken.php

Lines changed: 0 additions & 82 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http\OAuth2;
4+
5+
/**
6+
* @api
7+
*/
8+
interface HasGrantType
9+
{
10+
/**
11+
* Authorization code
12+
*
13+
* - \[RFC6749] Section 4.1 ("Authorization Code Grant")
14+
* - \[OpenID.Core] Section 3.1 ("Authentication using the Authorization
15+
* Code Flow")
16+
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
17+
*/
18+
public const GRANT_AUTHORIZATION_CODE = 'authorization_code';
19+
20+
/**
21+
* Resource owner password
22+
*
23+
* - \[RFC6749] Section 4.3 ("Resource Owner Password Credentials Grant")
24+
*/
25+
public const GRANT_PASSWORD = 'password';
26+
27+
/**
28+
* Client credentials
29+
*
30+
* - \[RFC6749] Section 4.4 ("Client Credentials Grant")
31+
*/
32+
public const GRANT_CLIENT_CREDENTIALS = 'client_credentials';
33+
34+
/**
35+
* Device code
36+
*
37+
* - \[RFC8628] ("OAuth 2.0 Device Authorization Grant")
38+
*/
39+
public const GRANT_DEVICE_CODE = 'urn:ietf:params:oauth:grant-type:device_code';
40+
41+
/**
42+
* Refresh token
43+
*
44+
* - \[RFC6749] Section 6 ("Refreshing an Access Token")
45+
*/
46+
public const GRANT_REFRESH_TOKEN = 'refresh_token';
47+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Salient\Http\OAuth2;
4+
5+
/**
6+
* @api
7+
*/
8+
interface HasResponseType
9+
{
10+
/**
11+
* Authorization code
12+
*
13+
* - \[RFC6749] Section 4.1 ("Authorization Code Grant")
14+
* - \[OpenID.Core] Section 3.1 ("Authentication using the Authorization
15+
* Code Flow")
16+
*/
17+
public const RESPONSE_CODE = 'code';
18+
19+
/**
20+
* Token
21+
*
22+
* - \[RFC6749] Section 4.2 ("Implicit Grant")
23+
*/
24+
public const RESPONSE_TOKEN = 'token';
25+
26+
/**
27+
* ID token
28+
*
29+
* - \[OpenID.Core] Section 3.2 ("Authentication using the Implicit Flow")
30+
*/
31+
public const RESPONSE_ID_TOKEN = 'id_token';
32+
33+
/**
34+
* ID token + token
35+
*
36+
* - \[OpenID.Core] Section 3.2 ("Authentication using the Implicit Flow")
37+
*/
38+
public const RESPONSE_ID_TOKEN_TOKEN = 'id_token token';
39+
40+
/**
41+
* Authorization code + ID token
42+
*
43+
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
44+
*/
45+
public const RESPONSE_CODE_ID_TOKEN = 'code id_token';
46+
47+
/**
48+
* Authorization code + token
49+
*
50+
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
51+
*/
52+
public const RESPONSE_CODE_TOKEN = 'code token';
53+
54+
/**
55+
* Authorization code + ID token + token
56+
*
57+
* - \[OpenID.Core] Section 3.3 ("Authentication using the Hybrid Flow")
58+
*/
59+
public const RESPONSE_CODE_ID_TOKEN_TOKEN = 'code id_token token';
60+
}

0 commit comments

Comments
 (0)