Skip to content

[12.x] Disable password grant by default #1715

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 5 commits into from
Feb 9, 2024
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
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ Passport 12.0 no longer automatically loads migrations from its own migrations d
php artisan vendor:publish --tag=passport-migrations
```

### Password Grant Type

The password grant type is disabled by default. You may enable it by calling the `enablePasswordGrant` method in the `boot` method of your application's `App\Providers\AppServiceProvider` class:

```php
public function boot(): void
{
Passport::enablePasswordGrant();
}
```

## Upgrading To 11.0 From 10.x

### Minimum PHP Version
Expand Down
14 changes: 13 additions & 1 deletion src/Passport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Passport
*
* @var bool|null
*/
public static $passwordGrantEnabled = true;
public static $passwordGrantEnabled = false;

/**
* The default scope.
Expand Down Expand Up @@ -196,6 +196,18 @@ public static function enableImplicitGrant()
return new static;
}

/**
* Enable the password grant type.
*
* @return static
*/
public static function enablePasswordGrant()
{
static::$passwordGrantEnabled = true;

return new static;
}

/**
* Set the default scope(s). Multiple scopes may be an array or specified delimited by spaces.
*
Expand Down
6 changes: 6 additions & 0 deletions tests/Feature/AccessTokenControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public function testGettingAccessTokenWithPasswordGrant()
{
$this->withoutExceptionHandling();

Passport::enablePasswordGrant();

$password = 'foobar123';
$user = UserFactory::new()->create([
'email' => '[email protected]',
Expand Down Expand Up @@ -153,6 +155,8 @@ public function testGettingAccessTokenWithPasswordGrant()

public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
{
Passport::enablePasswordGrant();

$password = 'foobar123';
$user = UserFactory::new()->create([
'email' => '[email protected]',
Expand Down Expand Up @@ -196,6 +200,8 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()

public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
{
Passport::enablePasswordGrant();

$password = 'foobar123';
$user = UserFactory::new()->create([
'email' => '[email protected]',
Expand Down