-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve issuing pat * improve tests * upgrade guide * Update UPGRADE.md * Update ClientRepository.php --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
61644b3
commit 8375604
Showing
10 changed files
with
87 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,49 +269,6 @@ public function testGettingCustomResponseType() | |
$this->assertArrayHasKey('id_token', $decodedResponse); | ||
$this->assertSame('foo_bar_open_id_token', $decodedResponse['id_token']); | ||
} | ||
|
||
public function testPersonalAccessTokenRequestIsDisabled() | ||
{ | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make('foobar123'), | ||
]); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asPersonalAccessTokenClient()->create(); | ||
|
||
config([ | ||
'passport.personal_access_client.id' => $client->getKey(), | ||
'passport.personal_access_client.secret' => $client->plainSecret, | ||
]); | ||
|
||
$response = $this->post( | ||
'/oauth/token', | ||
[ | ||
'grant_type' => 'personal_access', | ||
'client_id' => $client->getKey(), | ||
'client_secret' => $client->plainSecret, | ||
'user_id' => $user->getKey(), | ||
'scope' => '', | ||
] | ||
); | ||
|
||
$response->assertStatus(400); | ||
|
||
$decodedResponse = $response->decodeResponseJson()->json(); | ||
|
||
$this->assertArrayNotHasKey('token_type', $decodedResponse); | ||
$this->assertArrayNotHasKey('expires_in', $decodedResponse); | ||
$this->assertArrayNotHasKey('access_token', $decodedResponse); | ||
|
||
$this->assertArrayHasKey('error', $decodedResponse); | ||
$this->assertSame('unsupported_grant_type', $decodedResponse['error']); | ||
$this->assertArrayHasKey('error_description', $decodedResponse); | ||
|
||
$token = $user->createToken('test'); | ||
|
||
$this->assertInstanceOf(\Laravel\Passport\PersonalAccessTokenResult::class, $token); | ||
} | ||
} | ||
|
||
class IdTokenResponse extends \League\OAuth2\Server\ResponseTypes\BearerTokenResponse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
namespace Laravel\Passport\Tests\Feature; | ||
|
||
use Illuminate\Contracts\Hashing\Hasher; | ||
use Illuminate\Foundation\Auth\User as Authenticatable; | ||
use Illuminate\Support\Facades\DB; | ||
use Laravel\Passport\Client; | ||
|
@@ -13,25 +12,17 @@ | |
use Orchestra\Testbench\Concerns\WithLaravelMigrations; | ||
use Workbench\Database\Factories\UserFactory; | ||
|
||
class PersonalAccessTokenFactoryTest extends PassportTestCase | ||
class PersonalAccessGrantTest extends PassportTestCase | ||
{ | ||
use WithLaravelMigrations; | ||
|
||
public function testIssueToken() | ||
{ | ||
$user = UserFactory::new()->create([ | ||
'email' => '[email protected]', | ||
'password' => $this->app->make(Hasher::class)->make('foobar123'), | ||
]); | ||
$user = UserFactory::new()->create(); | ||
|
||
/** @var Client $client */ | ||
$client = ClientFactory::new()->asPersonalAccessTokenClient()->create(); | ||
|
||
config([ | ||
'passport.personal_access_client.id' => $client->getKey(), | ||
'passport.personal_access_client.secret' => $client->plainSecret, | ||
]); | ||
|
||
Passport::tokensCan([ | ||
'foo' => 'Do foo', | ||
'bar' => 'Do bar', | ||
|
@@ -56,9 +47,6 @@ public function testIssueTokenWithDifferentProviders() | |
'auth.guards.api-admins' => ['driver' => 'passport', 'provider' => 'admins'], | ||
'auth.providers.customers' => ['driver' => 'eloquent', 'model' => CustomerProviderStub::class], | ||
'auth.guards.api-customers' => ['driver' => 'passport', 'provider' => 'customers'], | ||
'passport.personal_access_client' => ['id' => $client->getKey(), 'secret' => $client->plainSecret], | ||
'passport.personal_access_client.admins' => ['id' => $adminClient->getKey(), 'secret' => $adminClient->plainSecret], | ||
'passport.personal_access_client.customers' => ['id' => $customerClient->getKey(), 'secret' => $customerClient->plainSecret], | ||
]); | ||
|
||
$user = UserFactory::new()->create(); | ||
|
@@ -97,6 +85,28 @@ public function testIssueTokenWithDifferentProviders() | |
$this->assertEquals([$adminToken->token->id], $adminTokens); | ||
$this->assertEquals([$customerToken->token->id], $customerTokens); | ||
} | ||
|
||
public function testPersonalAccessTokenRequestIsDisabled() | ||
{ | ||
$user = UserFactory::new()->create(); | ||
$client = ClientFactory::new()->asPersonalAccessTokenClient()->create(); | ||
|
||
$response = $this->post('/oauth/token', [ | ||
'grant_type' => 'personal_access', | ||
'provider' => $user->getProvider(), | ||
'user_id' => $user->getKey(), | ||
'scope' => '', | ||
]); | ||
|
||
$response->assertStatus(400); | ||
$json = $response->json(); | ||
|
||
$this->assertSame('unsupported_grant_type', $json['error']); | ||
$this->assertArrayHasKey('error_description', $json); | ||
$this->assertArrayNotHasKey('access_token', $json); | ||
|
||
$this->assertInstanceOf(PersonalAccessTokenResult::class, $user->createToken('test')); | ||
} | ||
} | ||
|
||
class AdminProviderStub extends Authenticatable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters