Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d77b07

Browse files
committed
Improve passport grants
1 parent7c62a40 commit3d77b07

File tree

6 files changed

+88
-158
lines changed

6 files changed

+88
-158
lines changed

‎src/Lodash/Auth/Passport/Grants/EmulateUserGrant.php‎

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
useDateInterval;
88
useIlluminate\Support\Arr;
99
useLaravel\Passport\Bridge\AccessToken;
10-
useLeague\OAuth2\Server\Entities\ClientEntityInterface;
1110
useLeague\OAuth2\Server\Entities\UserEntityInterface;
1211
useLeague\OAuth2\Server\Exception\OAuthServerException;
13-
useLeague\OAuth2\Server\Grant\AbstractGrant;
1412
useLeague\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
1513
useLeague\OAuth2\Server\RequestEvent;
1614
useLeague\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
@@ -20,17 +18,15 @@
2018
usePsr\Http\Message\ServerRequestInterface;
2119

2220
usefunctionevent;
23-
usefunctionis_null;
2421

25-
class EmulateUserGrantextendsAbstractGrant
22+
class EmulateUserGrantextendsGrant
2623
{
27-
protectedreadonlyAuthServiceContract$authService;
24+
publicconststringIDENTIFIER ='emulate';
2825

2926
publicfunction__construct(
30-
AuthServiceContract$authService,
27+
protectedreadonlyAuthServiceContract$authService,
3128
RefreshTokenRepositoryInterface$refreshTokenRepository,
3229
) {
33-
$this->authService =$authService;
3430
$this->setRefreshTokenRepository($refreshTokenRepository);
3531
$this->refreshTokenTTL =newDateInterval('P1M');
3632
}
@@ -79,31 +75,6 @@ public function getRefreshToken(AccessToken $token): void
7975
$this->issueRefreshToken($token);
8076
}
8177

82-
publicfunctiongetIdentifier():string
83-
{
84-
return'emulate';
85-
}
86-
87-
protectedfunctionvalidateClient(ServerRequestInterface$request):ClientEntityInterface
88-
{
89-
[$basicAuthUser,] =$this->getBasicAuthCredentials($request);
90-
91-
$clientId =$this->getRequestParameter('client_id',$request,$basicAuthUser);
92-
if (is_null($clientId)) {
93-
throw OAuthServerException::invalidRequest('client_id');
94-
}
95-
96-
// Get client without validating secret
97-
$client =$this->clientRepository->getClientEntity($clientId);
98-
99-
if (!$clientinstanceof ClientEntityInterface) {
100-
$this->getEmitter()->emit(newRequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED,$request));
101-
throw OAuthServerException::invalidClient($request);
102-
}
103-
104-
return$client;
105-
}
106-
10778
protectedfunctionvalidateUser(
10879
UserEntityInterface$user,
10980
ServerRequestInterface$request,

‎src/Lodash/Auth/Passport/Grants/GoogleAccessTokenGrant.php‎

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
namespaceLongman\LaravelLodash\Auth\Passport\Grants;
66

77
useDateInterval;
8-
useLeague\OAuth2\Server\Entities\ClientEntityInterface;
98
useLeague\OAuth2\Server\Entities\UserEntityInterface;
109
useLeague\OAuth2\Server\Exception\OAuthServerException;
11-
useLeague\OAuth2\Server\Grant\AbstractGrant;
1210
useLeague\OAuth2\Server\RequestEvent;
1311
useLeague\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
1412
useLongman\LaravelLodash\Auth\Contracts\AuthServiceContract;
@@ -18,15 +16,14 @@
1816

1917
usefunctionis_null;
2018

21-
class GoogleAccessTokenGrantextendsAbstractGrant
19+
class GoogleAccessTokenGrantextendsGrant
2220
{
23-
protectedreadonlyAuthServiceContract$authService;
21+
publicconststringIDENTIFIER ='google_access_token';
2422

2523
publicfunction__construct(
26-
AuthServiceContract$authService,
24+
protectedreadonlyAuthServiceContract$authService,
2725
RefreshTokenBridgeRepositoryContract$refreshTokenRepository,
2826
) {
29-
$this->authService =$authService;
3027
$this->setRefreshTokenRepository($refreshTokenRepository);
3128
$this->refreshTokenTTL =newDateInterval('P1M');
3229
}
@@ -35,7 +32,7 @@ public function respondToAccessTokenRequest(
3532
ServerRequestInterface$request,
3633
ResponseTypeInterface$responseType,
3734
DateInterval$accessTokenTtl,
38-
) {
35+
):ResponseTypeInterface {
3936
// Validate request
4037
$client =$this->validateClient($request);
4138
$scopes =$this->validateScopes($this->getRequestParameter('scope',$request));
@@ -58,31 +55,6 @@ public function respondToAccessTokenRequest(
5855
return$responseType;
5956
}
6057

61-
publicfunctiongetIdentifier():string
62-
{
63-
return'google_access_token';
64-
}
65-
66-
protectedfunctionvalidateClient(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 ($clientinstanceof ClientEntityInterface ===false) {
79-
$this->getEmitter()->emit(newRequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED,$request));
80-
throw OAuthServerException::invalidClient($request);
81-
}
82-
83-
return$client;
84-
}
85-
8658
protectedfunctionvalidateUser(ServerRequestInterface$request):UserEntityInterface
8759
{
8860
$googleToken =$this->getRequestParameter('token',$request);

‎src/Lodash/Auth/Passport/Grants/GoogleIdTokenGrant.php‎

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
namespaceLongman\LaravelLodash\Auth\Passport\Grants;
66

77
useDateInterval;
8-
useLeague\OAuth2\Server\Entities\ClientEntityInterface;
98
useLeague\OAuth2\Server\Entities\UserEntityInterface;
109
useLeague\OAuth2\Server\Exception\OAuthServerException;
11-
useLeague\OAuth2\Server\Grant\AbstractGrant;
1210
useLeague\OAuth2\Server\RequestEvent;
1311
useLeague\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
1412
useLongman\LaravelLodash\Auth\Contracts\AuthServiceContract;
@@ -18,15 +16,14 @@
1816

1917
usefunctionis_null;
2018

21-
class GoogleIdTokenGrantextendsAbstractGrant
19+
class GoogleIdTokenGrantextendsGrant
2220
{
23-
protectedreadonlyAuthServiceContract$authService;
21+
publicconststringIDENTIFIER ='google_id_token';
2422

2523
publicfunction__construct(
26-
AuthServiceContract$authService,
24+
protectedreadonlyAuthServiceContract$authService,
2725
RefreshTokenBridgeRepositoryContract$refreshTokenRepository,
2826
) {
29-
$this->authService =$authService;
3027
$this->setRefreshTokenRepository($refreshTokenRepository);
3128
$this->refreshTokenTTL =newDateInterval('P1M');
3229
}
@@ -35,7 +32,7 @@ public function respondToAccessTokenRequest(
3532
ServerRequestInterface$request,
3633
ResponseTypeInterface$responseType,
3734
DateInterval$accessTokenTtl,
38-
) {
35+
):ResponseTypeInterface {
3936
// Validate request
4037
$client =$this->validateClient($request);
4138
$scopes =$this->validateScopes($this->getRequestParameter('scope',$request));
@@ -58,31 +55,6 @@ public function respondToAccessTokenRequest(
5855
return$responseType;
5956
}
6057

61-
publicfunctiongetIdentifier():string
62-
{
63-
return'google_id_token';
64-
}
65-
66-
protectedfunctionvalidateClient(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 ($clientinstanceof ClientEntityInterface ===false) {
79-
$this->getEmitter()->emit(newRequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED,$request));
80-
throw OAuthServerException::invalidClient($request);
81-
}
82-
83-
return$client;
84-
}
85-
8658
protectedfunctionvalidateUser(ServerRequestInterface$request):UserEntityInterface
8759
{
8860
$googleToken =$this->getRequestParameter('token',$request);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespaceLongman\LaravelLodash\Auth\Passport\Grants;
6+
7+
useLeague\OAuth2\Server\Entities\ClientEntityInterface;
8+
useLeague\OAuth2\Server\Exception\OAuthServerException;
9+
useLeague\OAuth2\Server\Grant\AbstractGrant;
10+
useLeague\OAuth2\Server\RequestEvent;
11+
useOverride;
12+
usePsr\Http\Message\ServerRequestInterface;
13+
14+
usefunctionis_null;
15+
16+
abstractclass Grantextends AbstractGrant
17+
{
18+
publicfunctiongetIdentifier():string
19+
{
20+
returnstatic::IDENTIFIER;
21+
}
22+
23+
#[Override]
24+
protectedfunctionvalidateClient(ServerRequestInterface$request):ClientEntityInterface
25+
{
26+
$clientId =$this->getRequestParameter('client_id',$request);
27+
if (is_null($clientId)) {
28+
throw OAuthServerException::invalidRequest('client_id');
29+
}
30+
31+
// Get client without validating secret
32+
$client =$this->clientRepository->getClientEntity($clientId);
33+
34+
if (!$clientinstanceof ClientEntityInterface) {
35+
$this->getEmitter()->emit(newRequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED,$request));
36+
throw OAuthServerException::invalidClient($request);
37+
}
38+
39+
return$client;
40+
}
41+
}

‎src/Lodash/Auth/Passport/Grants/InternalGrant.php‎

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66

77
useDateInterval;
88
useLaravel\Passport\Bridge\AccessToken;
9-
useLeague\OAuth2\Server\Entities\ClientEntityInterface;
109
useLeague\OAuth2\Server\Entities\UserEntityInterface;
1110
useLeague\OAuth2\Server\Exception\OAuthServerException;
12-
useLeague\OAuth2\Server\Grant\AbstractGrant;
1311
useLeague\OAuth2\Server\RequestEvent;
1412
useLeague\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
1513
useLongman\LaravelLodash\Auth\Contracts\AuthServiceContract;
@@ -19,15 +17,14 @@
1917

2018
usefunctionis_null;
2119

22-
class InternalGrantextendsAbstractGrant
20+
class InternalGrantextendsGrant
2321
{
24-
protectedreadonlyAuthServiceContract$authService;
22+
publicconststringIDENTIFIER ='internal';
2523

2624
publicfunction__construct(
27-
AuthServiceContract$authService,
25+
protectedreadonlyAuthServiceContract$authService,
2826
RefreshTokenBridgeRepositoryContract$refreshTokenRepository,
2927
) {
30-
$this->authService =$authService;
3128
$this->setRefreshTokenRepository($refreshTokenRepository);
3229
$this->refreshTokenTTL =newDateInterval('P1M');
3330
}
@@ -64,31 +61,6 @@ public function getRefreshToken(AccessToken $token): void
6461
$this->issueRefreshToken($token);
6562
}
6663

67-
publicfunctiongetIdentifier():string
68-
{
69-
return'internal';
70-
}
71-
72-
protectedfunctionvalidateClient(ServerRequestInterface$request):ClientEntityInterface
73-
{
74-
[$basicAuthUser,] =$this->getBasicAuthCredentials($request);
75-
76-
$clientId =$this->getRequestParameter('client_id',$request,$basicAuthUser);
77-
if (is_null($clientId)) {
78-
throw OAuthServerException::invalidRequest('client_id');
79-
}
80-
81-
// Get client without validating secret
82-
$client =$this->clientRepository->getClientEntity($clientId);
83-
84-
if ($clientinstanceof ClientEntityInterface ===false) {
85-
$this->getEmitter()->emit(newRequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED,$request));
86-
throw OAuthServerException::invalidClient($request);
87-
}
88-
89-
return$client;
90-
}
91-
9264
protectedfunctionvalidateUser(ServerRequestInterface$request):UserEntityInterface
9365
{
9466
$login =$this->getRequestParameter('login',$request);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp