Skip to content

Commit

Permalink
Allow OAuth Scopes customization (nabeelio#1829)
Browse files Browse the repository at this point in the history
Co-authored-by: Nabeel S. <[email protected]>
  • Loading branch information
arthurpar06 and nabeelio authored Jul 15, 2024
1 parent 912331c commit 01704d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/Http/Controllers/Auth/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,22 @@ public function redirectToProvider(string $provider): RedirectResponse
if (!config('services.discord.enabled')) {
abort(404);
}
return Socialite::driver('discord')->scopes(['identify'])->redirect();

$requiredScopes = ['identify'];
$envScopes = config('services.discord.scopes', []);
$scopes = array_unique(array_merge($envScopes, $requiredScopes));

return Socialite::driver('discord')->scopes($scopes)->redirect();
case 'ivao':
return Socialite::driver('ivao')->redirect();
$scopes = config('services.ivao.scopes', []);

return Socialite::driver('ivao')->scopes($scopes)->redirect();
case 'vatsim':
return Socialite::driver('vatsim')->scopes(['email'])->redirect();
$requiredScopes = ['email'];
$envScopes = config('services.vatsim.scopes', []);
$scopes = array_unique(array_merge($envScopes, $requiredScopes));

return Socialite::driver('vatsim')->scopes($scopes)->redirect();
default:
abort(404);
}
Expand Down
3 changes: 3 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'enabled' => env('DISCORD_OAUTH_ENABLED', false),
'client_id' => env('DISCORD_CLIENT_ID'),
'client_secret' => env('DISCORD_CLIENT_SECRET'),
'scopes' => env('DISCORD_SCOPES', '') === '' ? [] : explode(',', env('DISCORD_SCOPES', '')),
'redirect' => '/oauth/discord/callback',

// optional
Expand All @@ -45,6 +46,7 @@
'enabled' => env('VATSIM_OAUTH_ENABLED', false),
'client_id' => env('VATSIM_CLIENT_ID'),
'client_secret' => env('VATSIM_CLIENT_SECRET'),
'scopes' => env('VATSIM_SCOPES', '') === '' ? [] : explode(',', env('VATSIM_SCOPES', '')),
'redirect' => '/oauth/vatsim/callback',

// For local development only
Expand All @@ -55,6 +57,7 @@
'enabled' => env('IVAO_OAUTH_ENABLED', false),
'client_id' => env('IVAO_CLIENT_ID'),
'client_secret' => env('IVAO_CLIENT_SECRET'),
'scopes' => env('IVAO_SCOPES', '') === '' ? [] : explode(',', env('IVAO_SCOPES', '')),
'redirect' => '/oauth/ivao/callback',
],
];

0 comments on commit 01704d6

Please sign in to comment.