Skip to content

Commit f2d6e9e

Browse files
[12.x] Disable password grant by default (#1715)
* disable password grant by default * add `enablePasswordGrant` method * update upgrade guide * Update UPGRADE.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 7888c91 commit f2d6e9e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

UPGRADE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ Passport 12.0 no longer automatically loads migrations from its own migrations d
1212
php artisan vendor:publish --tag=passport-migrations
1313
```
1414

15+
### Password Grant Type
16+
17+
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:
18+
19+
```php
20+
public function boot(): void
21+
{
22+
Passport::enablePasswordGrant();
23+
}
24+
```
25+
1526
## Upgrading To 11.0 From 10.x
1627

1728
### Minimum PHP Version

src/Passport.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Passport
2626
*
2727
* @var bool|null
2828
*/
29-
public static $passwordGrantEnabled = true;
29+
public static $passwordGrantEnabled = false;
3030

3131
/**
3232
* The default scope.
@@ -196,6 +196,18 @@ public static function enableImplicitGrant()
196196
return new static;
197197
}
198198

199+
/**
200+
* Enable the password grant type.
201+
*
202+
* @return static
203+
*/
204+
public static function enablePasswordGrant()
205+
{
206+
static::$passwordGrantEnabled = true;
207+
208+
return new static;
209+
}
210+
199211
/**
200212
* Set the default scope(s). Multiple scopes may be an array or specified delimited by spaces.
201213
*

tests/Feature/AccessTokenControllerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function testGettingAccessTokenWithPasswordGrant()
106106
{
107107
$this->withoutExceptionHandling();
108108

109+
Passport::enablePasswordGrant();
110+
109111
$password = 'foobar123';
110112
$user = UserFactory::new()->create([
111113
'email' => '[email protected]',
@@ -153,6 +155,8 @@ public function testGettingAccessTokenWithPasswordGrant()
153155

154156
public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
155157
{
158+
Passport::enablePasswordGrant();
159+
156160
$password = 'foobar123';
157161
$user = UserFactory::new()->create([
158162
'email' => '[email protected]',
@@ -196,6 +200,8 @@ public function testGettingAccessTokenWithPasswordGrantWithInvalidPassword()
196200

197201
public function testGettingAccessTokenWithPasswordGrantWithInvalidClientSecret()
198202
{
203+
Passport::enablePasswordGrant();
204+
199205
$password = 'foobar123';
200206
$user = UserFactory::new()->create([
201207
'email' => '[email protected]',

0 commit comments

Comments
 (0)