-
-
Notifications
You must be signed in to change notification settings - Fork 16
Segregate the methods of the AuthenticationMethodInterface #114
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Auth; | ||
|
|
||
| use Psr\Http\Message\ServerRequestInterface; | ||
|
|
||
| /** | ||
| * The interface that should be implemented by individual authentication methods. | ||
| */ | ||
| interface AuthenticatorInterface | ||
| { | ||
| /** | ||
| * Authenticates the identity based on information available from request. | ||
| * | ||
| * @param ServerRequestInterface $request Request to get identity information from. | ||
| * | ||
| * @return IdentityInterface|null An instance of identity or null if there is no match. | ||
| */ | ||
| public function authenticate(ServerRequestInterface $request): ?IdentityInterface; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Yiisoft\Auth; | ||
|
|
||
| use Psr\Http\Message\ResponseInterface; | ||
|
|
||
| /** | ||
| * The interface that should be implemented by response upon authentication failure. | ||
| */ | ||
| interface ChallengeInterface | ||
| { | ||
| /** | ||
| * Adds challenge to response upon authentication failure. | ||
| * For example, some appropriate HTTP headers may be added. | ||
| * | ||
| * @param ResponseInterface $response Response to modify. | ||
| * | ||
| * @return ResponseInterface Modified response. | ||
| */ | ||
| public function challenge(ResponseInterface $response): ResponseInterface; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,8 @@ | |
|
|
||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Yiisoft\Auth\AuthenticationMethodInterface; | ||
| use Yiisoft\Auth\AuthenticatorInterface; | ||
| use Yiisoft\Auth\ChallengeInterface; | ||
| use Yiisoft\Auth\IdentityInterface; | ||
| use Yiisoft\Auth\IdentityWithTokenRepositoryInterface; | ||
| use Yiisoft\Http\Header; | ||
|
|
@@ -28,7 +29,7 @@ | |
| * RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] | ||
| * ``` | ||
| */ | ||
| final class HttpBasic implements AuthenticationMethodInterface | ||
| final class HttpBasic implements AuthenticatorInterface, ChallengeInterface | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That should be capped for this release. |
||
| { | ||
| private string $realm = 'api'; | ||
| private ?string $tokenType = null; | ||
|
|
@@ -162,7 +163,7 @@ | |
| { | ||
| return array_map( | ||
| static fn($value) => $value === '' ? null : $value, | ||
| explode(':', base64_decode(substr($authToken, 6)), 2), | ||
|
Check warning on line 166 in src/Method/HttpBasic.php
|
||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,8 @@ | |
|
|
||
| namespace Yiisoft\Auth\Method; | ||
|
|
||
| use Psr\Http\Message\ResponseInterface; | ||
| use Psr\Http\Message\ServerRequestInterface; | ||
| use Yiisoft\Auth\AuthenticationMethodInterface; | ||
| use Yiisoft\Auth\AuthenticatorInterface; | ||
| use Yiisoft\Auth\IdentityInterface; | ||
| use Yiisoft\Auth\IdentityWithTokenRepositoryInterface; | ||
|
|
||
|
|
@@ -15,7 +14,7 @@ | |
| * | ||
| * @see https://tools.ietf.org/html/rfc6265 | ||
| */ | ||
| final class HttpCookie implements AuthenticationMethodInterface | ||
| final class HttpCookie implements AuthenticatorInterface | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be kept for this release. |
||
| { | ||
| private string $cookieName = 'access-token'; | ||
| private ?string $tokenType = null; | ||
|
|
@@ -35,11 +34,6 @@ public function authenticate(ServerRequestInterface $request): ?IdentityInterfac | |
| return $this->identityRepository->findIdentityByToken($authToken, $this->tokenType); | ||
| } | ||
|
|
||
| public function challenge(ResponseInterface $response): ResponseInterface | ||
| { | ||
| return $response; | ||
| } | ||
|
|
||
| /** | ||
| * @psalm-immutable | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be kept for this release.