Skip to content

Commit 4253511

Browse files
committed
chore: upgraded package for laravel 8
1 parent c897b65 commit 4253511

File tree

7 files changed

+134
-17
lines changed

7 files changed

+134
-17
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
],
1515
"require": {
1616
"php": ">=7.1",
17-
"illuminate/support": "^5.5 || ^6.0",
18-
"jenssegers/mongodb": "3.3.* || 3.4.* || 3.5.* || 3.6.*",
19-
"laravel/passport": "6.0.* || 7.0.* || 7.4.* || 7.5.* || ^8.0 || ^9.0"
17+
"illuminate/support": "^8.0",
18+
"mongodb/laravel-mongodb": "^3.8",
19+
"laravel/passport": "^10.0"
2020
},
2121
"autoload": {
2222
"psr-4": {

src/Passport/AuthCode.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class AuthCode extends Model
1313
*/
1414
protected $table = 'oauth_auth_codes';
1515

16+
/**
17+
* Indicates if the IDs are auto-incrementing.
18+
*
19+
* @var bool
20+
*/
21+
public $incrementing = false;
22+
1623
/**
1724
* The guarded attributes on the model.
1825
*
@@ -38,6 +45,20 @@ class AuthCode extends Model
3845
'expires_at',
3946
];
4047

48+
/**
49+
* Indicates if the model should be timestamped.
50+
*
51+
* @var bool
52+
*/
53+
public $timestamps = false;
54+
55+
/**
56+
* The "type" of the primary key ID.
57+
*
58+
* @var string
59+
*/
60+
protected $keyType = 'string';
61+
4162
/**
4263
* Get the client that owns the authentication code.
4364
*
@@ -47,4 +68,14 @@ public function client()
4768
{
4869
return $this->hasMany(Client::class);
4970
}
71+
72+
/**
73+
* Get the current connection name for the model.
74+
*
75+
* @return string|null
76+
*/
77+
public function getConnectionName()
78+
{
79+
return config('passport.storage.database.connection') ?? $this->connection;
80+
}
5081
}

src/Passport/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace DesignMyNight\Mongodb\Passport;
44

5-
use Jenssegers\Mongodb\Eloquent\Model;
5+
use Laravel\Passport\Client as BaseClient;
66

7-
class Client extends Model
7+
class Client extends BaseClient
88
{
99
/**
1010
* The database table used by the model.

src/Passport/PersonalAccessClient.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ public function client()
2929
{
3030
return $this->belongsTo(Client::class);
3131
}
32+
33+
/**
34+
* Get the current connection name for the model.
35+
*
36+
* @return string|null
37+
*/
38+
public function getConnectionName()
39+
{
40+
return config('passport.storage.database.connection') ?? $this->connection;
41+
}
3242
}

src/Passport/PersonalAccessTokenFactory.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace DesignMyNight\Mongodb\Passport;
44

5-
use Zend\Diactoros\Response;
6-
use Zend\Diactoros\ServerRequest;
7-
use Lcobucci\JWT\Parser as JwtParser;
8-
use League\OAuth2\Server\AuthorizationServer;
9-
use \Laravel\Passport\ClientRepository;
5+
use Laravel\Passport\ClientRepository;
106
use Laravel\Passport\PersonalAccessTokenResult;
117
use Laravel\Passport\TokenRepository;
8+
use Laravel\Passport\Passport;
9+
use Lcobucci\JWT\Parser as JwtParser;
10+
use League\OAuth2\Server\AuthorizationServer;
11+
use Nyholm\Psr7\Response;
12+
use Nyholm\Psr7\ServerRequest;
13+
use Psr\Http\Message\ServerRequestInterface;
1214

1315
class PersonalAccessTokenFactory
1416
{
@@ -37,6 +39,8 @@ class PersonalAccessTokenFactory
3739
* The JWT token parser instance.
3840
*
3941
* @var \Lcobucci\JWT\Parser
42+
*
43+
* @deprecated This property will be removed in a future Passport version.
4044
*/
4145
protected $jwt;
4246

@@ -92,14 +96,16 @@ public function make($userId, $name, array $scopes = [])
9296
* @param \Laravel\Passport\Client $client
9397
* @param mixed $userId
9498
* @param array $scopes
95-
* @return \Zend\Diactoros\ServerRequest
99+
* @return \Psr\Http\Message\ServerRequestInterface
96100
*/
97101
protected function createRequest($client, $userId, array $scopes)
98102
{
103+
$secret = Passport::$hashesClientSecrets ? $this->clients->getPersonalAccessClientSecret() : $client->secret;
104+
99105
return (new ServerRequest)->withParsedBody([
100106
'grant_type' => 'personal_access',
101107
'client_id' => $client->id,
102-
'client_secret' => $client->secret,
108+
'client_secret' => $secret,
103109
'user_id' => $userId,
104110
'scope' => implode(' ', $scopes),
105111
]);
@@ -108,10 +114,10 @@ protected function createRequest($client, $userId, array $scopes)
108114
/**
109115
* Dispatch the given request to the authorization server.
110116
*
111-
* @param \Zend\Diactoros\ServerRequest $request
117+
* @param Psr\Http\Message\ServerRequestInterface $request
112118
* @return array
113119
*/
114-
protected function dispatchRequestToAuthorizationServer(ServerRequest $request)
120+
protected function dispatchRequestToAuthorizationServer(ServerRequestInterface $request)
115121
{
116122
return json_decode($this->server->respondToAccessTokenRequest(
117123
$request, new Response

src/Passport/RefreshToken.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class RefreshToken extends Model
1313
*/
1414
protected $table = 'oauth_refresh_tokens';
1515

16+
/**
17+
* The "type" of the primary key ID.
18+
*
19+
* @var string
20+
*/
21+
protected $keyType = 'string';
22+
1623
/**
1724
* Indicates if the IDs are auto-incrementing.
1825
*
@@ -81,4 +88,14 @@ public function transient()
8188
{
8289
return false;
8390
}
91+
92+
/**
93+
* Get the current connection name for the model.
94+
*
95+
* @return string|null
96+
*/
97+
public function getConnectionName()
98+
{
99+
return config('passport.storage.database.connection') ?? $this->connection;
100+
}
84101
}

src/Passport/Token.php

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ class Token extends Model
2020
*/
2121
protected $table = 'oauth_access_tokens';
2222

23+
/**
24+
* The "type" of the primary key ID.
25+
*
26+
* @var string
27+
*/
28+
protected $keyType = 'string';
29+
2330
/**
2431
* Indicates if the IDs are auto-incrementing.
2532
*
@@ -71,7 +78,9 @@ public function user()
7178
{
7279
$provider = config('auth.guards.api.provider');
7380

74-
return $this->belongsTo(config('auth.providers.' . $provider . '.model'));
81+
$model = config('auth.providers.'.$provider.'.model');
82+
83+
return $this->belongsTo($model, 'user_id', (new $model)->getKeyName());
7584
}
7685

7786
/**
@@ -83,8 +92,42 @@ public function user()
8392
*/
8493
public function can($scope)
8594
{
86-
return in_array('*', $this->scopes) ||
87-
array_key_exists($scope, array_flip($this->scopes));
95+
if (in_array('*', $this->scopes)) {
96+
return true;
97+
}
98+
99+
$scopes = Passport::$withInheritedScopes
100+
? $this->resolveInheritedScopes($scope)
101+
: [$scope];
102+
103+
foreach ($scopes as $scope) {
104+
if (array_key_exists($scope, array_flip($this->scopes))) {
105+
return true;
106+
}
107+
}
108+
109+
return false;
110+
}
111+
112+
/**
113+
* Resolve all possible scopes.
114+
*
115+
* @param string $scope
116+
* @return array
117+
*/
118+
protected function resolveInheritedScopes($scope)
119+
{
120+
$parts = explode(':', $scope);
121+
122+
$partsCount = count($parts);
123+
124+
$scopes = [];
125+
126+
for ($i = 1; $i <= $partsCount; $i++) {
127+
$scopes[] = implode(':', array_slice($parts, 0, $i));
128+
}
129+
130+
return $scopes;
88131
}
89132

90133
/**
@@ -117,4 +160,14 @@ public function transient()
117160
{
118161
return false;
119162
}
163+
164+
/**
165+
* Get the current connection name for the model.
166+
*
167+
* @return string|null
168+
*/
169+
public function getConnectionName()
170+
{
171+
return config('passport.storage.database.connection') ?? $this->connection;
172+
}
120173
}

0 commit comments

Comments
 (0)