A Complete Discord Provider for Laravel Socialite Package
kayckmatias/discord-socialite-provider is a Laravel package for a complete discord provider for laravel socialite package.
It currently has 3 GitHub stars and 14 downloads on Packagist (latest version 1.0.1).
Install it with composer require kayckmatias/discord-socialite-provider.
Discover more Laravel packages by kayckmatias
or browse all Laravel packages to compare alternatives.
Last updated
A Discord OAuth2 provider for the Laravel Socialite package. This package allows you to easily integrate Discord login with Laravel applications using Socialite with extra features for Discord OAuth2.
Install the package via Composer:
composer require kayckmatias/discord-socialite-provider
Add the service provider to the config/app.php (only if you're using Laravel version <5.5 or not using package auto-discovery):
'providers' => [
KayckMatias\Laravel\Socialite\DiscordServiceProvider::class,
],
Add your Discord credentials to the config/services.php file:
'discord' => [
'client_id' => env('DISCORD_CLIENT_ID'),
'client_secret' => env('DISCORD_CLIENT_SECRET'),
'redirect' => '/auth/discord/callback',
]
You need to register your application with Discord to obtain the credentials required for OAuth2. You can register a new application at the Discord Developer Portal.
Once you have your credentials, add the following environment variables to your .env file:
DISCORD_CLIENT_ID=your-client-id
DISCORD_CLIENT_SECRET=your-client-secret
Once the package is installed and configured, you can use Discord as a provider with Laravel Socialite.
In your controller, use the Socialite facade to redirect the user to the Discord authentication page:
use Laravel\Socialite\Facades\Socialite;
public function redirectToDiscord()
{
return Socialite::driver('discord')->redirect();
}
Once the user authorizes the app, Discord will redirect the user back to your application's callback URL. You can handle the callback and retrieve user information as follows:
use Laravel\Socialite\Facades\Socialite;
public function handleDiscordCallback()
{
$user = Socialite::driver('discord')->user();
// Access user details
$id = $user->getId();
$name = $user->getName();
$nickname = $user->getNickname();
$email = $user->getEmail();
$avatar = $user->getAvatar();
// Handle the user data
}
To request with custom scopes, you can use the setScopes method:
return Socialite::driver('discord')
->setScopes(['identify', 'email', 'bot'])
->redirect();
To request additional permissions, you can use the withPermissions method:
return Socialite::driver('discord')
->withPermissions('1689934340028480')
->redirect();
If you're working with a bot, you can use asBot to bot scope instead default identify scope:
return Socialite::driver('discord')
->asBot()
->redirect();
To add the guild_id= parameter to the Discord authorization URL, use the withGuildId method:
return Socialite::driver('discord')
->withGuildId('0000000000000000000')
->redirect();
To add the prompt=none parameter to the Discord authorization URL, use the withConsent method:
return Socialite::driver('discord')
->withConsent()
->redirect();
This package is open-source and licensed under the MIT license.
For more information about Discord OAuth, please visit the Discord OAuth2 Documentation. For more information about Socialite, please visit the Socialite Documentation.
For any issues, feel free to open a ticket on the GitHub repository.