Skip to content

[11.x] Get model PK instead of forcibly id column #1626

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

Merged
merged 8 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/views/authorize.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
@csrf

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

<input type="hidden" name="state" value="{{ $request->state }}">
<input type="hidden" name="client_id" value="{{ $client->id }}">
<input type="hidden" name="client_id" value="{{ $client->getKey() }}">
<input type="hidden" name="auth_token" value="{{ $authToken }}">
<button class="btn btn-danger">Cancel</button>
</form>
Expand Down
2 changes: 1 addition & 1 deletion src/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function createPersonalAccessClient($userId, $name, $redirect)
{
return tap($this->create($userId, $name, $redirect, null, true), function ($client) {
$accessClient = Passport::personalAccessClient();
$accessClient->client_id = $client->id;
$accessClient->client_id = $client->getKey();
$accessClient->save();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/ClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ protected function outputClientDetails(Client $client)
$this->line('');
}

$this->line('<comment>Client ID:</comment> '.$client->id);
$this->line('<comment>Client ID:</comment> '.$client->getKey());
$this->line('<comment>Client secret:</comment> '.$client->plainSecret);
}
}
2 changes: 1 addition & 1 deletion src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public static function actingAsClient($client, $scopes = [], $guard = 'api')
{
$token = app(self::tokenModel());

$token->client_id = $client->id;
$token->client_id = $client->getKey();
$token->setRelation('client', $client);

$token->scopes = $scopes;
Expand Down
2 changes: 1 addition & 1 deletion src/PersonalAccessTokenFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function createRequest($client, $userId, array $scopes)

return (new ServerRequest('POST', 'not-important'))->withParsedBody([
'grant_type' => 'personal_access',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $secret,
'user_id' => $userId,
'scope' => implode(' ', $scopes),
Expand Down
24 changes: 12 additions & 12 deletions tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public function testGettingAccessTokenWithClientCredentialsGrant()
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'client_credentials',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret,
]
);
Expand Down Expand Up @@ -93,13 +93,13 @@ public function testGettingAccessTokenWithClientCredentialsGrantInvalidClientSec
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'client_credentials',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret.'foo',
]
);
Expand Down Expand Up @@ -137,13 +137,13 @@ public function testGettingAccessTokenWithPasswordGrant()
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'password',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret,
'username' => $user->email,
'password' => $password,
Expand Down Expand Up @@ -184,13 +184,13 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'password',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret,
'username' => $user->email,
'password' => $password.'foo',
Expand Down Expand Up @@ -227,13 +227,13 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'password',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret.'foo',
'username' => $user->email,
'password' => $password,
Expand Down Expand Up @@ -274,13 +274,13 @@ public function testGettingCustomResponseType()
$user->save();

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

$response = $this->post(
'/oauth/token',
[
'grant_type' => 'client_credentials',
'client_id' => $client->id,
'client_id' => $client->getKey(),
'client_secret' => $client->secret,
]
);
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/PersonalAccessTokenFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laravel\Passport\Tests\Unit;

use Laravel\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\PersonalAccessTokenFactory;
use Laravel\Passport\PersonalAccessTokenResult;
Expand Down Expand Up @@ -56,7 +57,7 @@ public function test_access_token_can_be_created()
}
}

class PersonalAccessTokenFactoryTestClientStub
class PersonalAccessTokenFactoryTestClientStub extends Client
{
public $id = 1;

Expand Down