1. Go to this page and download the library: Download winter/wn-sso-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
winter / wn-sso-plugin example snippets
return [
'enabled_providers' => [
'github',
],
];
return [
/**
* List of enabled providers
* Only providers in this array will appear on the login page
*/
'enabled_providers' => [
'google',
'github',
// Add more providers here
],
/**
* Disable native username/password authentication
* Forces users to authenticate via SSO only
* If only one provider is enabled, redirects directly to it
*/
'prevent_native_auth' => false,
/**
* Allow new user registration via SSO
* If false, only existing users can login via SSO
*/
'allow_registration' => false,
/**
* Require explicit permission for SSO connections
* Users must explicitly allow each provider (
// Add more providers...
],
];
Event::listen('winter.sso.google.authenticating', function () {
// Check if authentication should proceed
if (!some_condition()) {
return false; // Aborts authentication
}
});
Event::listen('winter.sso.google.authenticated', function ($ssoUser) {
// $ssoUser is Laravel\Socialite\AbstractUser
Log::info('User authenticated via Google', [
'email' => $ssoUser->getEmail(),
'id' => $ssoUser->getId(),
]);
});
Event::listen('winter.sso.google.beforeRegister', function ($ssoUser) {
// Only allow company email addresses
if (!str_ends_with($ssoUser->getEmail(), '@mycompany.com')) {
throw new AuthenticationException('Only company emails allowed');
}
});
Event::listen('winter.sso.google.registered', function ($user, $ssoUser) {
// $user is Backend\Models\User
// $ssoUser is Laravel\Socialite\AbstractUser
$user->fill([
'first_name' => $ssoUser->user['given_name'] ?? null,
'last_name' => $ssoUser->user['family_name'] ?? null,
]);
$user->save();
});
Event::listen('winter.sso.google.beforeLogin', function ($user, $ssoUser) {
// Perform checks before allowing login
if ($user->is_suspended) {
throw new AuthenticationException('Account suspended');
}
});
Event::listen('winter.sso.google.afterLogin', function ($user, $ssoUser) {
// Track login
Log::info('User logged in via Google', ['user_id' => $user->id]);
// Update last login timestamp
$user->last_sso_login = now();
$user->save();
});
// Get SSO data for a specific provider
$googleId = $user->getSsoValue('google', 'id');
$token = $user->getSsoValue('google', 'token');
// Set SSO data
$user->setSsoValues('google', [
'id' => '12345',
'token' => 'abc123',
'custom_field' => 'value',
]);
// First login: ID stored
$user->setSsoValues('google', ['id' => '123456']);
// Later login: ID must match
if ($ssoUser->getId() !== $user->getSsoValue('google', 'id')) {
throw new InvalidSsoIdException();
}