Search by

eighteen73 / laravel-sso

edjeavons

Abstract SSO logic into a reusable, self-contained Laravel package.

Package info

github.com/eighteen73/laravel-sso

pkg:composer/eighteen73/laravel-sso

Statistics

Installs: 789

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-12-02 16:03 UTC

This package is auto-updated.

Last update: 2026-12-02 16:03:57 UTC


README

A reusable Laravel package for integrating Single Sign-On (SSO) using Laravel Socialite, with built-in support for Logto and Filament.

Note: This is an opinionated, internal project designed primarily to meet the requirements of eighteen73. While it is open-sourced and feedback is welcome, its development is driven by our specific needs and workflows.

Features

  • Automatic Socialite provider registration for Logto.
  • Dedicated sso_accounts table to map SSO identities to local users.
  • Optional user model helpers for SSO account relationships and login policy checks.
  • Configurable user resolution with opt-in auto-creation logic.
  • Automatic integration with Filament panels: login button, SSO-aware login page, global sign-out and session checks.
  • App-only sign-out by default, an optional global sign-out route, and OpenID Connect back-channel logout.
  • Access revalidation every few minutes, with profile claims kept in sync.
  • ID token verification against Logto's published keys.
  • A sso.profile route to the user's Logto account page.
  • php artisan sso:check to verify the setup against Logto.
  • Translatable user-facing messages.
  • Support for multiple SSO connections per user.

Installation

You can install the package via composer:

composer require eighteen73/laravel-sso

The migrations load automatically. Optionally publish the config file, then run the migrations:

php artisan vendor:publish --tag="sso-config"
php artisan migrate

Add your Logto application's details to .env. LOGTO_BASE_URL is the Logto endpoint without the trailing /oidc.

LOGTO_BASE_URL=https://auth.example.com
LOGTO_CLIENT_ID=
LOGTO_CLIENT_SECRET=

Then check the setup against Logto. The command lists the URIs and permissions to register:

php artisan sso:check

In the Logto Admin Console, the application (a Traditional Web application) needs:

  • Redirect URI: {APP_URL}/sso/callback
  • Post sign-out redirect URI: {APP_URL}, or LOGTO_POST_LOGOUT_REDIRECT_URI if set
  • Back-channel logout URI: {APP_URL}/sso/backchannel-logout, with Is session required turned on
  • Permissions: profile, email and offline_access, plus anything added to sso.scopes
  • Rules: who may use the application (app-level access control)

MFA is enforced through Logto's own multi-factor auth settings rather than by this package.

Configuration

The configuration file is located at config/sso.php. You can customise the following:

  • provider: The Socialite driver to use (defaulting to logto).
  • auto_create_users: Whether to create a new local user if the SSO email is not found. This is disabled by default, so unknown SSO users are rejected unless you explicitly opt into provisioning.
  • require_verified_email: When an SSO identity is not yet linked, it is matched to (or used to create) a local user by email. This is only allowed when Logto reports email_verified: true. Enabled by default; set SSO_REQUIRE_VERIFIED_EMAIL=false to disable. Identities already linked by provider ID are unaffected.
  • scopes: Extra scopes to request on top of openid, profile and email. Logto only returns some claims when their scope is requested, for example ['custom_data', 'roles'].
  • revalidate_after: How often, in minutes, to confirm that a signed-in SSO user still has access. See Access Revalidation. Defaults to 10; set SSO_REVALIDATE_AFTER=null to disable it.
  • redirect_path: The path to redirect to after a successful login.
  • user_resolver: The action class used to map SSO data to a local user.
  • filament: Settings for Filament integration, including which panels to display the SSO button on.

Filament Integration

On the panels in sso.filament.panels, the package needs no further setup. It:

  • shows the "Sign in with eighteen73" button, with any SSO error above it;
  • replaces Filament's default login page with Eighteen73\SSO\Filament\Login, which:
    • sends browsers that last signed in through SSO straight to Logto, which signs the user in silently while its session lasts. It never does this straight after a sign-out or while showing an SSO error. Add ?password=1 to the login URL to show the form instead;
    • refuses password logins for users whose requiresSsoLogin() is true (by default, users linked to the current provider), so access removed in Logto cannot be bypassed with a password. The check runs after the password is verified;
  • keeps Filament's sign-out app-only (see Sessions and Sign-out), but marks the session so the login page then shows the form rather than sending the user straight back to Logto;
  • adds the RevalidateSsoSession middleware to the authenticated routes, and registers it as Livewire persistent middleware so actions on an open page are checked too.

Panels with a custom login page keep it; extend Eighteen73\SSO\Filament\Login to get the same behaviour. Outside Filament, add RevalidateSsoSession to your authenticated routes yourself.

Sessions and Sign-out

  • No remember-me. SSO sign-ins never set Laravel's remember-me cookie. Logto's own session (14 days by default) keeps users signed in: when the app session expires, signing in again through Logto needs no password.
  • App sign-out. Signing out of an app (including Filament's sign-out) ends only that app's session, as with sites that use "Sign in with Google". The user stays signed in to Logto, so "Sign in with eighteen73" signs them back in without a password. On a shared computer, use global sign-out instead.
  • Global sign-out. route('sso.logout') ends the app session and the Logto session via Logto's end-session endpoint, then returns to LOGTO_POST_LOGOUT_REDIRECT_URI (default APP_URL). Link to it where users should be able to sign out everywhere, and register that URL as a post sign-out redirect URI in Logto. Through back-channel logout, other apps the user is signed in to follow.
  • Back-channel logout. When a user signs out of Logto elsewhere, Logto calls /sso/backchannel-logout with a signed logout token. The package verifies it and signs out the app session that belongs to that Logto session (matched by sid) on its next request, through RevalidateSsoSession. If the token has no sid, every earlier session of that user is signed out. Logto only puts sid in ID tokens when the application's back-channel logout has Is session required turned on, so turn it on before users sign in. Logto must be able to reach the URI, so this does not work against a local development site.
  • ID tokens are verified. At sign-in, the ID token's signature (against Logto's published keys), issuer, audience, expiry and subject are checked before the user is signed in.

Profile Link

route('sso.profile') redirects to the user's account page in Logto, so apps can link to it anywhere. It uses sso.profile_url (SSO_PROFILE_URL) if set, otherwise Logto's Account Center at {LOGTO_BASE_URL}/account, which must be enabled in Logto.

Translations

User-facing text, including the button label and every error, is in lang/en/messages.php. Publish it to reword it:

php artisan vendor:publish --tag="sso-lang"

Access Revalidation

A local session would otherwise outlive changes made in Logto, such as removing a user from an application's access rules. The package confirms access every revalidate_after minutes (10 by default) and signs out users who have lost it.

How it works:

  • Logins request offline_access with prompt=consent (unless login_parameters sets a prompt), as Logto only issues a refresh token when both are present. Allow offline_access for the application in Logto.
  • On a request from a user with an SSO account whose last check is older than the interval, the middleware uses the refresh token. Logto checks the application's access rules again for refresh token requests.
  • If Logto refuses the refresh token (invalid_grant, or access_denied when the user no longer matches the application's access rules), the user is signed out with a message. Users with no refresh token, such as those signed in before revalidation was enabled, are asked to sign in again.
  • After a successful check, the user's claims are read again from Logto and synced (see Automatic Attribute Syncing), so profile changes such as a new nickname arrive without signing in again.
  • If Logto cannot be reached or returns another error, the user stays signed in, the error is reported, and the check is retried after a minute.
  • The check is per SSO account, so all of a user's sessions share the result. Idle users are checked on their next request.
  • Users without an SSO account for the current provider are not checked, and can still sign in with a password.

Customising User Resolution

By default, the package links an SSO identity to an existing local user by matching the SSO email address. If no local user exists, login fails unless auto_create_users is explicitly enabled.

The built-in auto-creation path only fills common name, email, and password attributes. If your application requires additional columns such as first_name, last_name, is_enabled, role, tenant IDs, or any other app-specific state, create a custom action that implements Eighteen73\SSO\Actions\ResolveUserContract and update the user_resolver in your config.

You can also extend the default resolver if you only need to add behavior around the package's built-in linking logic:

namespace App\Actions;

use Eighteen73\SSO\Actions\ResolveUser;
use Laravel\Socialite\Contracts\User as ProviderUser;
use Illuminate\Contracts\Auth\Authenticatable;

class CustomResolveUser extends ResolveUser
{
    public function resolve(string $provider, ProviderUser $ssoUser): Authenticatable
    {
        $user = parent::resolve($provider, $ssoUser);

        // Add your custom logic here

        return $user;
    }
}

User Model Helpers

Your application user model can opt into SSO relationship and policy helpers by using the HasSsoAccounts trait:

namespace App\Models;

use Eighteen73\SSO\Concerns\HasSsoAccounts;
use Eighteen73\SSO\Contracts\HasSsoAccounts as HasSsoAccountsContract;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements HasSsoAccountsContract
{
    use HasSsoAccounts;

    public function requiresSsoLogin(): bool
    {
        return $this->role->requiresSso();
    }
}

By default, requiresSsoLogin() returns true for users linked to the current provider (sso.provider), which the package's Filament login page uses to refuse their password logins. canUsePasswordLogin() returns true. Override either in your application when roles, tenants, or other local rules need different behaviour.

User Profile Management URL

The trait also provides a getSsoProfileUrl(?string $provider = null) method that returns the same URL as route('sso.profile'): sso.profile_url if set, otherwise Logto's Account Center:

// Returns sso.profile_url, or {LOGTO_BASE_URL}/account
$profileUrl = $user->getSsoProfileUrl();

SSO User Details & Attribute Syncing

The package automatically captures all raw OpenID Connect (OIDC) claims returned by Logto / Socialite on every login and stores them as JSON in the sso_accounts.claims column.

Accessing Claims via HasSsoAccounts Trait

// Retrieve all raw claims returned during the last login
$claims = $user->getSsoClaims();

// Retrieve a specific claim (e.g. nickname, locale, or Logto custom data)
// custom_data is only returned when 'custom_data' is in sso.scopes
$department = $user->getSsoClaim('custom_data.department');

// Get the user's avatar URL
$avatar = $user->getSsoAvatar();

// Logto global roles (requires 'roles' in sso.scopes)
$roles = $user->getSsoRoles();
$isAdmin = $user->hasSsoRole('admin');

Claims are stored at sign-in and refreshed by each successful access revalidation, so changes made in Logto (such as a new nickname or role) arrive within revalidate_after minutes of the user's next request. With revalidation disabled, they arrive at the next SSO sign-in.

Automatic Attribute Syncing

By default, the package syncs SSO claims to matching columns on your local User model on login: name (the full display name), nickname (the short name) and avatar_url. Columns that do not exist are skipped, and claims that are not set (Logto omits empty profile values) leave the column unchanged. Given and family name are not used. You can configure this in config/sso.php:

'sync_attributes_on_login' => env('SSO_SYNC_ATTRIBUTES', true),

'attribute_map' => [
    'name'       => 'name',
    'nickname'   => 'nickname',
    'avatar_url' => 'avatar',
],

In Logto, set the short name as nickname in the user's profile.

Upgrading from the Zitadel version

This release replaces Zitadel with Logto and is not backwards compatible. The last Zitadel release is tagged zitadel-final.

  • socialiteproviders/zitadel is replaced by socialiteproviders/logto, and the provider name changes from zitadel to logto.
  • ZITADEL_* environment variables are replaced by LOGTO_*, and services.zitadel by services.logto.
  • The sso.zitadel options (enforce_mfa, select_account) are removed. Enforce MFA in Logto instead.
  • getSsoProfileUrl() returns sso.profile_url, or Logto's Account Center ({LOGTO_BASE_URL}/account) when it is not set.
  • sso.remember is removed: SSO sign-ins never set a remember-me cookie, so back-channel logout can always match the session. Logto's own session keeps users signed in.
  • The login page sends returning SSO users straight to Logto (?password=1 shows the form). Filament's sign-out stays app-only; link to route('sso.logout') to sign out of Logto too.
  • Register the back-channel logout URI ({APP_URL}/sso/backchannel-logout, with "Is session required" on) and the post sign-out redirect URI in Logto. php artisan sso:check lists them.
  • ID tokens are now verified at sign-in. A Logto application whose ID token fails verification (for example a mismatched LOGTO_BASE_URL) can no longer sign in.
  • Unlinked identities now need a verified email to be linked by email (see require_verified_email).
  • Run php artisan migrate for the new sso_accounts.validated_at column.
  • Access revalidation is on by default. Existing users have no refresh token, so they are asked to sign in again once, on their first request at least revalidate_after minutes after their last SSO login. The application in Logto must allow offline_access.
  • Users linked to the current provider can no longer sign in with a password on Filament panels that use the default login page.
  • Logto access rules are enforced through the application's Rules tab in Logto; denied users see a message on the login page.
  • The default attribute_map and auto-created users no longer use given or family name (first_name, last_name). They use name and nickname instead. Add the old mappings to your published config if you still need them.

Testing

The package uses Pest for testing. You can run the tests with:

./vendor/bin/pest

License

The MIT License (MIT). Please see License File for more information.