Laravel (Socialite)
See the Applications overview for prerequisites, configuration endpoints, and available scopes.
Install the Socialite OpenID Connect driver:
composer require socialiteproviders/openid-connect
Add the provider configuration to config/services.php:
'vouch' => [
'client_id' => env('VOUCH_CLIENT_ID'),
'client_secret' => env('VOUCH_CLIENT_SECRET'),
'redirect' => env('VOUCH_REDIRECT_URI', 'https://your-app.example.com/auth/vouch/callback'),
'discovery_url' => 'https://us.vouch.sh/.well-known/openid-configuration',
],
Register the event listener in app/Providers/EventServiceProvider.php:
protected $listen = [
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
\SocialiteProviders\OpenIDConnect\OpenIDConnectExtendSocialite::class . '@handle',
],
];
Add routes in routes/web.php:
use Laravel\Socialite\Facades\Socialite;
Route::get('/auth/vouch', function () {
return Socialite::driver('openid-connect')
->setConfig(config('services.vouch'))
->scopes(['openid', 'email'])
->redirect();
});
Route::get('/auth/vouch/callback', function () {
$user = Socialite::driver('openid-connect')
->setConfig(config('services.vouch'))
->user();
$localUser = User::updateOrCreate(
['vouch_id' => $user->getId()],
[
'name' => $user->getName(),
'email' => $user->getEmail(),
]
);
Auth::login($localUser);
return redirect('/dashboard');
});