Skip to main content

Overview

revolution/socialite-discord is a driver package that adds Discord OAuth2 support to Laravel Socialite. Discord is not included among Socialite’s built-in providers. Install this package and you can immediately use Socialite::driver('discord') to add Discord login to your application.
For a general guide on Laravel Socialite, see the Socialite guide.

Installation

composer require revolution/socialite-discord

Configuration

Register your app in the Discord Developer Portal

Create an application in the Discord Developer Portal and retrieve the Client ID and Client Secret from the OAuth2 section. Add your callback URL (e.g. https://example.com/auth/discord/callback) to the Redirects list.

config/services.php

'discord' => [
    'client_id'     => env('DISCORD_CLIENT_ID'),
    'client_secret' => env('DISCORD_CLIENT_SECRET'),
    'redirect'      => env('DISCORD_REDIRECT'),
],

.env

DISCORD_CLIENT_ID=your-client-id
DISCORD_CLIENT_SECRET=your-client-secret
DISCORD_REDIRECT=https://example.com/auth/discord/callback

Basic usage

1

Define routes

Add a redirect route and a callback route to routes/web.php.
use App\Http\Controllers\SocialiteController;

Route::get('auth/discord', [SocialiteController::class, 'login']);
Route::get('auth/discord/callback', [SocialiteController::class, 'callback']);
2

Create the controller

<?php

namespace App\Http\Controllers;

use Laravel\Socialite\Facades\Socialite;

class SocialiteController extends Controller
{
    public function login()
    {
        return Socialite::driver('discord')->redirect();
    }

    public function callback()
    {
        $discordUser = Socialite::driver('discord')->user();

        // $discordUser->getId()        Discord user ID
        // $discordUser->getName()      Username
        // $discordUser->getEmail()     Email address (requires email scope)
        // $discordUser->getAvatar()    Avatar URL
        // $discordUser->token          Access token

        $user = \App\Models\User::updateOrCreate(
            ['discord_id' => $discordUser->getId()],
            ['name' => $discordUser->getName()]
        );

        \Illuminate\Support\Facades\Auth::login($user);

        return redirect('/dashboard');
    }
}

Scopes

Discord OAuth2 uses scopes to control which data your application can access. The default scope is identify only.
public function login()
{
    return Socialite::driver('discord')
                    ->setScopes(['identify', 'email', 'guilds', 'guilds.join'])
                    ->redirect();
}
Common scopes:
ScopeData available
identifyUser ID, username, avatar (default)
emailEmail address
guildsList of servers the user belongs to
guilds.joinPermission to add the user to a server
For a full list of scopes, see the Discord OAuth2 documentation.

Saving the user and logging in

A typical callback implementation that persists the user to the database and logs them in:
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Laravel\Socialite\Facades\Socialite;

public function callback()
{
    $discordUser = Socialite::driver('discord')->user();

    $user = User::updateOrCreate(
        ['discord_id' => $discordUser->getId()],
        [
            'name'          => $discordUser->getName(),
            'email'         => $discordUser->getEmail(),
            'discord_token' => $discordUser->token,
        ]
    );

    Auth::login($user);

    return redirect('/dashboard');
}
The email scope is required to retrieve an email address. Without it, getEmail() may return null.

Comparison with other Socialite drivers

This package is implemented using Socialite::extend(), the official method for adding custom drivers. It exposes the same API as any built-in provider. For details on how custom providers work and how Socialite::extend() is used, see the Socialite guide.
For the latest information, refer to the GitHub repository.
Last modified on April 30, 2026