Skip to content
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: 3 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ If you prefer to use the new structure, you may create a migration to apply the

```php
Schema::table('oauth_clients', function (Blueprint $table) {
$table->nullableMorphs('owner')->after('user_id');
$table->after('user_id', function (Blueprint $table) {
$table->nullableMorphs('owner');
});

$table->after('provider', function (Blueprint $table) {
$table->text('redirect_uris');
Expand Down
4 changes: 3 additions & 1 deletion src/Console/ClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Laravel\Passport\Client;
use Laravel\Passport\ClientRepository;
use Laravel\Passport\Passport;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'passport:client')]
Expand Down Expand Up @@ -149,7 +150,8 @@ protected function createAuthCodeClient(ClientRepository $clients): Client
? ! $this->option('public')
: $this->components->confirm('Would you like to make this client confidential?', true);

$enableDeviceFlow = $this->confirm('Would you like to enable the device authorization flow for this client?');
$enableDeviceFlow = Passport::$deviceCodeGrantEnabled &&
$this->confirm('Would you like to enable the device authorization flow for this client?');

return $clients->createAuthorizationCodeGrantClient(
$this->option('name'), explode(',', $redirect), $confidential, null, $enableDeviceFlow
Expand Down
6 changes: 2 additions & 4 deletions tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public function testGettingAccessTokenWithClientCredentialsGrant()
$this->assertArrayHasKey('expires_in', $decodedResponse);
$this->assertArrayHasKey('access_token', $decodedResponse);
$this->assertSame('Bearer', $decodedResponse['token_type']);
$expiresInSeconds = 31536000;
$this->assertEqualsWithDelta($expiresInSeconds, $decodedResponse['expires_in'], 5);
$this->assertEqualsWithDelta(31536000, $decodedResponse['expires_in'], 2);
}

public function testGettingAccessTokenWithClientCredentialsGrantInvalidClientSecret()
Expand Down Expand Up @@ -131,8 +130,7 @@ public function testGettingAccessTokenWithPasswordGrant()
$this->assertArrayHasKey('access_token', $decodedResponse);
$this->assertArrayHasKey('refresh_token', $decodedResponse);
$this->assertSame('Bearer', $decodedResponse['token_type']);
$expiresInSeconds = 31536000;
$this->assertEqualsWithDelta($expiresInSeconds, $decodedResponse['expires_in'], 5);
$this->assertEqualsWithDelta(31536000, $decodedResponse['expires_in'], 2);
}

public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/AuthorizationCodeGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testIssueAccessToken()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
->middleware('auth:api');
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/AuthorizationCodeGrantWithPkceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testIssueAccessToken()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

$refreshToken = $json['refresh_token'];

Expand All @@ -103,7 +103,7 @@ public function testIssueAccessToken()

$this->assertArrayHasKey('access_token', $newToken);
$this->assertArrayHasKey('refresh_token', $newToken);
$this->assertSame(31536000, $newToken['expires_in']);
$this->assertEqualsWithDelta(31536000, $newToken['expires_in'], 2);
$this->assertSame('Bearer', $newToken['token_type']);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/ClientCredentialsGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testIssueAccessToken()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayNotHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => response('response'))
->middleware([EnsureClientIsResourceOwner::using(['create', 'delete'])]);
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testIssueAccessTokenWithAllScopes()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayNotHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => response('response'))
->middleware([EnsureClientIsResourceOwner::using(['create', 'delete'])]);
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/DeviceAuthorizationGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testIssueAccessToken()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
->middleware('auth:api');
Expand Down Expand Up @@ -254,7 +254,7 @@ public function testPublicClient()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);
}

public function testUnauthorizedClient()
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/ImplicitGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testIssueAccessToken()
$this->assertArrayHasKey('access_token', $params);
$this->assertArrayNotHasKey('refresh_token', $params);
$this->assertSame('Bearer', $params['token_type']);
$this->assertSame('31536000', $params['expires_in']);
$this->assertEqualsWithDelta(31536000, $params['expires_in'], 2);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
->middleware('auth:api');
Expand Down Expand Up @@ -145,7 +145,7 @@ public function testSkipsAuthorizationWhenHasGrantedScopes()
$this->assertArrayHasKey('access_token', $params);
$this->assertArrayNotHasKey('refresh_token', $params);
$this->assertSame('Bearer', $params['token_type']);
$this->assertSame('31536000', $params['expires_in']);
$this->assertEqualsWithDelta(31536000, $params['expires_in'], 2);
}

public function testValidateAuthorizationRequest()
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/PasswordGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testIssueToken()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
->middleware('auth:api');
Expand Down Expand Up @@ -77,7 +77,7 @@ public function testIssueTokenWithAllScopes()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
->middleware('auth:api');
Expand Down Expand Up @@ -167,7 +167,7 @@ public function testPublicClient()
$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame('Bearer', $json['token_type']);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);
}

public function testUnauthorizedClient()
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/PersonalAccessGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testIssueToken()
$this->assertArrayHasKey('accessToken', $result->toArray());
$this->assertSame($token->getKey(), $result->accessTokenId);
$this->assertSame('Bearer', $result->tokenType);
$this->assertSame(31536000, $result->expiresIn);
$this->assertEqualsWithDelta(31536000, $result->expiresIn, 2);
$this->assertSame($client->getKey(), $token->client_id);
$this->assertSame($user->getAuthIdentifier(), $token->user_id);
$this->assertSame(['bar'], $token->scopes);
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/RefreshTokenGrantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testRefreshingToken()

$this->assertArrayHasKey('access_token', $newToken);
$this->assertArrayHasKey('refresh_token', $newToken);
$this->assertSame(31536000, $newToken['expires_in']);
$this->assertEqualsWithDelta(31536000, $newToken['expires_in'], 2);
$this->assertSame('Bearer', $newToken['token_type']);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
Expand Down Expand Up @@ -92,7 +92,7 @@ public function testRefreshingTokenWithoutRevoking()

$this->assertArrayHasKey('access_token', $newToken);
$this->assertArrayHasKey('refresh_token', $newToken);
$this->assertSame(31536000, $newToken['expires_in']);
$this->assertEqualsWithDelta(31536000, $newToken['expires_in'], 2);
$this->assertSame('Bearer', $newToken['token_type']);

Route::get('/foo', fn (Request $request) => $request->user()->currentAccessToken()->toJson())
Expand All @@ -117,7 +117,7 @@ public function testRefreshingTokenWithoutRevoking()

$this->assertArrayHasKey('access_token', $json);
$this->assertArrayHasKey('refresh_token', $json);
$this->assertSame(31536000, $json['expires_in']);
$this->assertEqualsWithDelta(31536000, $json['expires_in'], 2);
$this->assertSame('Bearer', $json['token_type']);
}

Expand Down