Skip to content

Commit 1d8204e

Browse files
authored
[11.x] Get model PK instead of forcibly id column (#1626)
* Get model PK instead of forcibly id column * Get model PK instead of forcibly id column in tests * Get model PK instead of forcibly id column in command * Get model PK instead of forcibly id column in repository * Get model PK instead of forcibly id column in Passport * stub extending from model * Fix namespace order * Get model PK instead of forcibly id column in blade
1 parent b7bc60c commit 1d8204e

7 files changed

+20
-19
lines changed

resources/views/authorize.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
@csrf
6969

7070
<input type="hidden" name="state" value="{{ $request->state }}">
71-
<input type="hidden" name="client_id" value="{{ $client->id }}">
71+
<input type="hidden" name="client_id" value="{{ $client->getKey() }}">
7272
<input type="hidden" name="auth_token" value="{{ $authToken }}">
7373
<button type="submit" class="btn btn-success btn-approve">Authorize</button>
7474
</form>
@@ -79,7 +79,7 @@
7979
@method('DELETE')
8080

8181
<input type="hidden" name="state" value="{{ $request->state }}">
82-
<input type="hidden" name="client_id" value="{{ $client->id }}">
82+
<input type="hidden" name="client_id" value="{{ $client->getKey() }}">
8383
<input type="hidden" name="auth_token" value="{{ $authToken }}">
8484
<button class="btn btn-danger">Cancel</button>
8585
</form>

src/ClientRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function createPersonalAccessClient($userId, $name, $redirect)
167167
{
168168
return tap($this->create($userId, $name, $redirect, null, true), function ($client) {
169169
$accessClient = Passport::personalAccessClient();
170-
$accessClient->client_id = $client->id;
170+
$accessClient->client_id = $client->getKey();
171171
$accessClient->save();
172172
});
173173
}

src/Console/ClientCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ protected function outputClientDetails(Client $client)
167167
$this->line('');
168168
}
169169

170-
$this->line('<comment>Client ID:</comment> '.$client->id);
170+
$this->line('<comment>Client ID:</comment> '.$client->getKey());
171171
$this->line('<comment>Client secret:</comment> '.$client->plainSecret);
172172
}
173173
}

src/Passport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public static function actingAsClient($client, $scopes = [], $guard = 'api')
370370
{
371371
$token = app(self::tokenModel());
372372

373-
$token->client_id = $client->id;
373+
$token->client_id = $client->getKey();
374374
$token->setRelation('client', $client);
375375

376376
$token->scopes = $scopes;

src/PersonalAccessTokenFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ protected function createRequest($client, $userId, array $scopes)
9898

9999
return (new ServerRequest('POST', 'not-important'))->withParsedBody([
100100
'grant_type' => 'personal_access',
101-
'client_id' => $client->id,
101+
'client_id' => $client->getKey(),
102102
'client_secret' => $secret,
103103
'user_id' => $userId,
104104
'scope' => implode(' ', $scopes),

tests/Feature/AccessTokenControllerTest.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public function testGettingAccessTokenWithClientCredentialsGrant()
5050
$user->save();
5151

5252
/** @var Client $client */
53-
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->id]);
53+
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]);
5454

5555
$response = $this->post(
5656
'/oauth/token',
5757
[
5858
'grant_type' => 'client_credentials',
59-
'client_id' => $client->id,
59+
'client_id' => $client->getKey(),
6060
'client_secret' => $client->secret,
6161
]
6262
);
@@ -93,13 +93,13 @@ public function testGettingAccessTokenWithClientCredentialsGrantInvalidClientSec
9393
$user->save();
9494

9595
/** @var Client $client */
96-
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->id]);
96+
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]);
9797

9898
$response = $this->post(
9999
'/oauth/token',
100100
[
101101
'grant_type' => 'client_credentials',
102-
'client_id' => $client->id,
102+
'client_id' => $client->getKey(),
103103
'client_secret' => $client->secret.'foo',
104104
]
105105
);
@@ -137,13 +137,13 @@ public function testGettingAccessTokenWithPasswordGrant()
137137
$user->save();
138138

139139
/** @var Client $client */
140-
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
140+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]);
141141

142142
$response = $this->post(
143143
'/oauth/token',
144144
[
145145
'grant_type' => 'password',
146-
'client_id' => $client->id,
146+
'client_id' => $client->getKey(),
147147
'client_secret' => $client->secret,
148148
'username' => $user->email,
149149
'password' => $password,
@@ -184,13 +184,13 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
184184
$user->save();
185185

186186
/** @var Client $client */
187-
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
187+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]);
188188

189189
$response = $this->post(
190190
'/oauth/token',
191191
[
192192
'grant_type' => 'password',
193-
'client_id' => $client->id,
193+
'client_id' => $client->getKey(),
194194
'client_secret' => $client->secret,
195195
'username' => $user->email,
196196
'password' => $password.'foo',
@@ -227,13 +227,13 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
227227
$user->save();
228228

229229
/** @var Client $client */
230-
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->id]);
230+
$client = ClientFactory::new()->asPasswordClient()->create(['user_id' => $user->getKey()]);
231231

232232
$response = $this->post(
233233
'/oauth/token',
234234
[
235235
'grant_type' => 'password',
236-
'client_id' => $client->id,
236+
'client_id' => $client->getKey(),
237237
'client_secret' => $client->secret.'foo',
238238
'username' => $user->email,
239239
'password' => $password,
@@ -274,13 +274,13 @@ public function testGettingCustomResponseType()
274274
$user->save();
275275

276276
/** @var Client $client */
277-
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->id]);
277+
$client = ClientFactory::new()->asClientCredentials()->create(['user_id' => $user->getKey()]);
278278

279279
$response = $this->post(
280280
'/oauth/token',
281281
[
282282
'grant_type' => 'client_credentials',
283-
'client_id' => $client->id,
283+
'client_id' => $client->getKey(),
284284
'client_secret' => $client->secret,
285285
]
286286
);

tests/Unit/PersonalAccessTokenFactoryTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Laravel\Passport\Tests\Unit;
44

5+
use Laravel\Passport\Client;
56
use Laravel\Passport\ClientRepository;
67
use Laravel\Passport\PersonalAccessTokenFactory;
78
use Laravel\Passport\PersonalAccessTokenResult;
@@ -56,7 +57,7 @@ public function test_access_token_can_be_created()
5657
}
5758
}
5859

59-
class PersonalAccessTokenFactoryTestClientStub
60+
class PersonalAccessTokenFactoryTestClientStub extends Client
6061
{
6162
public $id = 1;
6263

0 commit comments

Comments
 (0)