To add Sign in with Slack to Laravel 13, install Socialite, create a Slack app with the Sign in with Slack (OpenID Connect) feature, put its credentials under the slack-openid key in config/services.php and use Socialite::driver('slack-openid') in a redirect route and a callback route. This guide walks through the setup and a safe callback.
Targets: Laravel 13 (PHP 8.3 to 8.5) and laravel/socialite. The Socialite documentation lists both slack and slack-openid; this article uses slack-openid because it matches Slack's OpenID Connect sign-in. Confirm the driver name against the documentation for your installed version.
Step 1: Install Socialite
composer require laravel/socialiteStep 2: Create the Slack app
- Go to the Slack API site and choose Create New App, then From scratch.
- Pick a name and the workspace you will use for development.
- Open OAuth & Permissions and add your callback URL under Redirect URLs, for example
https://your-app.test/auth/slack/callback. - Under the user token scopes, add the OpenID scopes (
openid,profileandemail). - Copy the Client ID and Client Secret from Basic Information.
Slack requires an HTTPS redirect URL for most setups, so use a local tunnel or a local HTTPS domain such as the one your tool provides. Slack's screens change over time, so follow the labels you see.
Step 3: Add the credentials
SLACK_CLIENT_ID=your-client-id
SLACK_CLIENT_SECRET=your-client-secret
SLACK_REDIRECT_URI=https://your-app.test/auth/slack/callback'slack-openid' => [
'client_id' => env('SLACK_CLIENT_ID'),
'client_secret' => env('SLACK_CLIENT_SECRET'),
'redirect' => env('SLACK_REDIRECT_URI'),
],Add the array to config/services.php.
Step 4: Store the Slack ID on users
php artisan make:migration add_slack_id_to_users_table --table=userspublic function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->string('slack_id')->nullable()->unique()->after('email');
$table->string('password')->nullable()->change();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('slack_id');
});
}Add slack_id to the User model's $fillable array and run php artisan migrate.
Step 5: Create the controller
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
use Laravel\Socialite\Facades\Socialite;
use Throwable;
class SlackAuthController extends Controller
{
public function redirect(): RedirectResponse
{
return Socialite::driver('slack-openid')->redirect();
}
public function callback(): RedirectResponse
{
try {
$slackUser = Socialite::driver('slack-openid')->user();
} catch (Throwable $e) {
report($e);
return redirect('/login')->withErrors(['email' => 'Slack sign-in failed. Please try again.']);
}
$user = User::updateOrCreate(
['slack_id' => $slackUser->getId()],
[
'name' => $slackUser->getName() ?: 'Slack user',
'email' => $slackUser->getEmail(),
'email_verified_at' => now(),
'password' => Str::password(32),
]
);
Auth::login($user, remember: true);
return redirect()->intended('/dashboard');
}
}Step 6: Add the routes and the button
use App\Http\Controllers\SlackAuthController;
use Illuminate\Support\Facades\Route;
Route::get('/auth/slack/redirect', [SlackAuthController::class, 'redirect'])->name('slack.redirect');
Route::get('/auth/slack/callback', [SlackAuthController::class, 'callback']);<a href="{{ route('slack.redirect') }}">Sign in with Slack</a>Should I limit sign-in to one Slack workspace?
If the app is for your team only, check the workspace of the returned user before logging in, or use Slack's team parameter when redirecting. Without such a check, any Slack user can sign in and get an account in your application. Decide who is allowed and enforce it in the callback.
How do I test it?
- Open the app over the HTTPS URL that you registered.
- Click the Slack button and allow access.
- Confirm you reach
/dashboardand see the new user with aslack_id.
Common mistakes
- Wrong driver name: the services key and the driver name must match (
slack-openidin this article). - HTTP redirect URL: Slack may reject it. Use HTTPS.
- Missing OpenID scopes: without
openid,profileandemailthe user data is incomplete. - Allowing everyone: restrict sign-in if the app is internal.
- Cached config: run
php artisan config:clearafter changes.
FAQ
What is the difference between slack and slack-openid?
The slack-openid driver uses Slack's OpenID Connect sign-in, while slack is the older sign-in flow. Prefer the OpenID driver for new projects and check Slack's current guidance.
Can I post messages to Slack from Laravel too?
Yes, but that is a different feature: use incoming webhooks or the Slack notification channel.
Do I need a paid Slack plan?
No. Creating an app and using Sign in with Slack works on a free workspace.



