5
5
namespace Longman \LaravelLodash \Auth \Passport \Grants ;
6
6
7
7
use DateInterval ;
8
- use League \OAuth2 \Server \Entities \ClientEntityInterface ;
9
8
use League \OAuth2 \Server \Entities \UserEntityInterface ;
10
9
use League \OAuth2 \Server \Exception \OAuthServerException ;
11
- use League \OAuth2 \Server \Grant \AbstractGrant ;
12
10
use League \OAuth2 \Server \RequestEvent ;
13
11
use League \OAuth2 \Server \ResponseTypes \ResponseTypeInterface ;
14
12
use Longman \LaravelLodash \Auth \Contracts \AuthServiceContract ;
18
16
19
17
use function is_null ;
20
18
21
- class GoogleAccessTokenGrant extends AbstractGrant
19
+ class GoogleAccessTokenGrant extends Grant
22
20
{
23
- protected readonly AuthServiceContract $ authService ;
21
+ public const string IDENTIFIER = ' google_access_token ' ;
24
22
25
23
public function __construct (
26
- AuthServiceContract $ authService ,
24
+ protected readonly AuthServiceContract $ authService ,
27
25
RefreshTokenBridgeRepositoryContract $ refreshTokenRepository ,
28
26
) {
29
- $ this ->authService = $ authService ;
30
27
$ this ->setRefreshTokenRepository ($ refreshTokenRepository );
31
28
$ this ->refreshTokenTTL = new DateInterval ('P1M ' );
32
29
}
@@ -35,7 +32,7 @@ public function respondToAccessTokenRequest(
35
32
ServerRequestInterface $ request ,
36
33
ResponseTypeInterface $ responseType ,
37
34
DateInterval $ accessTokenTtl ,
38
- ) {
35
+ ): ResponseTypeInterface {
39
36
// Validate request
40
37
$ client = $ this ->validateClient ($ request );
41
38
$ scopes = $ this ->validateScopes ($ this ->getRequestParameter ('scope ' , $ request ));
@@ -58,31 +55,6 @@ public function respondToAccessTokenRequest(
58
55
return $ responseType ;
59
56
}
60
57
61
- public function getIdentifier (): string
62
- {
63
- return 'google_access_token ' ;
64
- }
65
-
66
- protected function validateClient (ServerRequestInterface $ request ): ClientEntityInterface
67
- {
68
- [$ basicAuthUser ,] = $ this ->getBasicAuthCredentials ($ request );
69
-
70
- $ clientId = $ this ->getRequestParameter ('client_id ' , $ request , $ basicAuthUser );
71
- if (is_null ($ clientId )) {
72
- throw OAuthServerException::invalidRequest ('client_id ' );
73
- }
74
-
75
- // Get client without validating secret
76
- $ client = $ this ->clientRepository ->getClientEntity ($ clientId );
77
-
78
- if ($ client instanceof ClientEntityInterface === false ) {
79
- $ this ->getEmitter ()->emit (new RequestEvent (RequestEvent::CLIENT_AUTHENTICATION_FAILED , $ request ));
80
- throw OAuthServerException::invalidClient ($ request );
81
- }
82
-
83
- return $ client ;
84
- }
85
-
86
58
protected function validateUser (ServerRequestInterface $ request ): UserEntityInterface
87
59
{
88
60
$ googleToken = $ this ->getRequestParameter ('token ' , $ request );
0 commit comments