Skip to content

Commit 1507155

Browse files
[13.x] Add an option to disable device code grant (#1842)
* add an option to disable device code grant * fix upgrade guide entry * force re-run tests
1 parent f0877ac commit 1507155

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

UPGRADE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ All the authorization view's rendering logic may be customized using the appropr
3232

3333
public function boot(): void
3434
{
35+
// By providing the view names...
3536
Passport::authorizationView('auth.oauth.authorize');
37+
Passport::deviceUserCodeView('auth.oauth.device.user-code');
38+
Passport::deviceAuthorizationView('auth.oauth.device.authorize');
39+
40+
// Or using conventional names under the given prefix...
41+
Passport::viewPrefix('auth.oauth');
3642
}
3743

3844
### Identify Clients by UUIDs

routes/web.php

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
'middleware' => 'web',
1616
]);
1717

18-
Route::get('/device', [
19-
'uses' => 'DeviceUserCodeController',
20-
'as' => 'device',
21-
'middleware' => 'web',
22-
]);
18+
if (Passport::$deviceCodeGrantEnabled) {
19+
Route::get('/device', [
20+
'uses' => 'DeviceUserCodeController',
21+
'as' => 'device',
22+
'middleware' => 'web',
23+
]);
2324

24-
Route::post('/device/code', [
25-
'uses' => 'DeviceCodeController',
26-
'as' => 'device.code',
27-
'middleware' => 'throttle',
28-
]);
25+
Route::post('/device/code', [
26+
'uses' => 'DeviceCodeController',
27+
'as' => 'device.code',
28+
'middleware' => 'throttle',
29+
]);
30+
}
2931

3032
$guard = config('passport.guard', null);
3133

@@ -45,20 +47,22 @@
4547
'as' => 'authorizations.deny',
4648
]);
4749

48-
Route::get('/device/authorize', [
49-
'uses' => 'DeviceAuthorizationController',
50-
'as' => 'device.authorizations.authorize',
51-
]);
50+
if (Passport::$deviceCodeGrantEnabled) {
51+
Route::get('/device/authorize', [
52+
'uses' => 'DeviceAuthorizationController',
53+
'as' => 'device.authorizations.authorize',
54+
]);
5255

53-
Route::post('/device/authorize', [
54-
'uses' => 'ApproveDeviceAuthorizationController',
55-
'as' => 'device.authorizations.approve',
56-
]);
56+
Route::post('/device/authorize', [
57+
'uses' => 'ApproveDeviceAuthorizationController',
58+
'as' => 'device.authorizations.approve',
59+
]);
5760

58-
Route::delete('/device/authorize', [
59-
'uses' => 'DenyDeviceAuthorizationController',
60-
'as' => 'device.authorizations.deny',
61-
]);
61+
Route::delete('/device/authorize', [
62+
'uses' => 'DenyDeviceAuthorizationController',
63+
'as' => 'device.authorizations.deny',
64+
]);
65+
}
6266

6367
if (Passport::$registersJsonApiRoutes) {
6468
Route::get('/tokens', [

src/Passport.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ class Passport
3030
*/
3131
public static bool $revokeRefreshTokenAfterUse = true;
3232

33+
/**
34+
* Indicates if the device authorization grant type is enabled.
35+
*/
36+
public static bool $deviceCodeGrantEnabled = true;
37+
3338
/**
3439
* Indicates if the implicit grant type is enabled.
3540
*/

src/PassportServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function (AuthorizationServer $server): void {
167167
);
168168
}
169169

170-
if (Route::has('passport.device')) {
170+
if (Passport::$deviceCodeGrantEnabled && Route::has('passport.device')) {
171171
$server->enableGrantType(
172172
$this->makeDeviceCodeGrant(), Passport::tokensExpireIn()
173173
);

0 commit comments

Comments
 (0)