### Example Callback URLs Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt These are example URLs for registering with OAuth providers. The panel-specific URL is used when routing is configured per panel, while the global callback URL is for stateful multi-panel setups. ```bash # Example callback URL to register in your GitHub OAuth app # (panel with path "admin", provider "github") https://example.com/admin/oauth/callback/github ``` ```bash # Global callback URL (works for all panels, stateful only) https://example.com/oauth/callback/github ``` -------------------------------- ### Install Filament Socialite Package Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Install the package via composer, publish and run its migration, and optionally publish other assets like config and views. Font Awesome is recommended for provider icons. ```bash composer require dutchcodingcompany/filament-socialite # Publish and run the migration php artisan vendor:publish --tag="filament-socialite-migrations" php artisan migrate # Optional: publish config, views, translations php artisan vendor:publish --tag="filament-socialite-config" php artisan vendor:publish --tag="filament-socialite-views" php artisan vendor:publish --tag="filament-socialite-translations" # Optional: Font Awesome brand icons for provider buttons composer require owenvoke/blade-fontawesome ``` -------------------------------- ### Install Blade Font Awesome Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Install the Blade Font Awesome package to use custom icons for login providers. ```bash composer require owenvoke/blade-fontawesome ``` -------------------------------- ### OAuth Callback URL Example Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md This is an example of a callback URL for a GitHub OAuth application. It includes a placeholder for the panel ID, allowing a single OAuth application to serve multiple Filament panels. ```url https://example.com/oauth/callback/github ``` -------------------------------- ### Multi-Panel OAuth Setup Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Configure independent OAuth providers and settings for different Filament panels by registering the plugin separately. Supports shared or distinct callback URLs. ```php // app/Providers/Filament/AdminPanelProvider.php ->plugin( FilamentSocialitePlugin::make() ->providers([ Provider::make('google')->label('Google')->icon('fab-google'), ]) ->domainAllowList(['acme.com']) ->registration(false) ) // app/Providers/Filament/CustomerPanelProvider.php ->plugin( FilamentSocialitePlugin::make() ->providers([ Provider::make('github')->label('GitHub')->icon('fab-github'), Provider::make('google')->label('Google')->icon('fab-google'), ]) ->registration(true) // customers can self-register ) // For a **shared callback URL** across all panels (one OAuth app registration), use the global route /oauth/callback/{provider} — the panel is identified from the encrypted `state` parameter. This requires stateful OAuth (not compatible with `->stateless(true)`). ``` -------------------------------- ### Install Filament Socialite via Composer Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Use this command to add the Filament Socialite package to your project. ```bash composer require dutchcodingcompany/filament-socialite ``` -------------------------------- ### External OAuth App Configuration Callback URL Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Example of a callback URL for a Filament panel with ID 'admin' and the 'github' provider. Ensure this matches your external OAuth app configuration. ```text https://example.com/admin/oauth/callback/github ``` -------------------------------- ### Configure Providers with Provider Class Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md Providers are now configured using the `Provider` class. The key should be passed to the `make()` function. This replaces the previous method of passing a plain array. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; FilamentSocialitePlugin::make() ->providers([ Provider::make('gitlab') ->label('GitLab') ->icon('fab-gitlab') ->color(Color::hex('#2f2a6b')), ]), ``` -------------------------------- ### Publish Configuration File Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md Run this command to replace or republish the configuration file when upgrading from 0.x.x to 1.x.x for Filament v3.x. ```bash sail artisan vendor:publish --provider="DutchCodingCompany\FilamentSocialite\FilamentSocialiteServiceProvider" ``` -------------------------------- ### Implement Create User Callback Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md The `setCreateUserCallback()` method has been renamed to `createUserUsing()`. This should now be called on the plugin instance, typically within the `boot` method of `AppServiceProvider.php`. ```php FilamentSocialitePlugin::make() // ... ->createUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) { // Logic to create a new user. }) ``` -------------------------------- ### Publish and Migrate Filament Socialite Assets Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Run these artisan commands to publish the package's migration files and then apply them to your database. ```bash php artisan vendor:publish --tag="filament-socialite-migrations" php artisan migrate ``` -------------------------------- ### Customize User Creation and Retrieval Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Use `createUserUsing` and `resolveUserUsing` methods to define custom logic for creating or retrieving users during the social login process. Ensure necessary imports are included. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; ->plugin( FilamentSocialitePlugin::make() // ... ->createUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) { // Logic to create a new user. }) ->resolveUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) { // Logic to retrieve an existing user. }) ... ``` -------------------------------- ### Implement Login Redirect Callback Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md The `setLoginRedirectCallback()` method has been renamed to `redirectAfterLoginUsing()`. This should now be called on the plugin instance, typically within the `boot` method of `AppServiceProvider.php`. ```php FilamentSocialitePlugin::make() // ... ->redirectAfterLoginUsing(function (string $provider, FilamentSocialiteUserContract $socialiteUser, FilamentSocialitePlugin $plugin) { // Change the redirect behaviour here. }) ``` -------------------------------- ### Configure Provider Scopes and Optional Parameters Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md Scopes and optional parameters for Socialite providers are now configured within the `->providers()` method using `scopes()` and `with()`, rather than in the `services.php` file. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; FilamentSocialitePlugin::make() ->providers([ Provider::make('gitlab') // ... ->scopes([ // Add scopes here. 'read:user', 'public_repo', ]), ->with([ // Add optional parameters here. 'hd' => 'example.com', ]), ]), ``` -------------------------------- ### Configure Individual OAuth Provider Options Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Define specific configurations for each OAuth provider using Provider::make(). Customize labels, icons, colors, button styles, stateless authentication, scopes, and conditional visibility. ```php use DutchCodingCompany\FilamentSocialite\Provider; use Filament\Support\Colors\Color; // Full example covering every available option $provider = Provider::make('gitlab') ->label('GitLab') // button label ->icon('fab-gitlab') // Blade icon name (e.g. blade-fontawesome) ->color(Color::hex('#2f2a6b')) // button colour (hex string or Filament color array) ->outlined(false) // filled vs outlined button style ->stateless(false) // set true for stateless OAuth (e.g. Apple) ->scopes(['read_user', 'read_api']) // additional OAuth scopes ->with(['hd' => 'example.com']) // optional OAuth parameters ->visible(fn () => app()->environment('production')); // conditional visibility // Stateless provider (e.g. Apple — cannot use state-based multi-panel route) $apple = Provider::make('apple') ->label('Apple') ->icon('fab-apple') ->stateless(true); ``` -------------------------------- ### Implement User Resolver Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md The `setUserResolver()` method has been renamed to `resolveUserUsing()`. This should now be called on the plugin instance, typically within the `boot` method of `AppServiceProvider.php`. ```php FilamentSocialitePlugin::make() // ... ->resolveUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) { // Logic to retrieve an existing user. }) ``` -------------------------------- ### Publish Other Filament Socialite Assets Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md These commands publish configuration, view, and translation files for Filament Socialite. ```bash php artisan vendor:publish --tag="filament-socialite-config" php artisan vendor:publish --tag="filament-socialite-views" php artisan vendor:publish --tag="filament-socialite-translations" ``` -------------------------------- ### Update Panel Configuration for Filament v3.x Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md Append this line to your panel configuration file (`App\Providers\Filament\YourPanelProvider`) to include the FilamentSocialite plugin when upgrading from 0.x.x to 1.x.x. ```php ->plugins([ DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin::make() ]) ``` -------------------------------- ### Configure Callback Middleware Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Customize the middleware stack for the OAuth callback route by editing the published config file. ```php // config/filament-socialite.php return [ 'middleware' => [ \Illuminate\Cookie\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, // Add your own middleware here, e.g.: // \App\Http\Middleware\TrustProxies::class, ], ]; ``` -------------------------------- ### Control New-User Registration Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Configure whether new users can automatically create accounts upon OAuth login. A closure allows for fine-grained control based on provider, OAuth user, and existing user data. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; use Illuminate\Contracts\Auth\Authenticatable; FilamentSocialitePlugin::make() // Simple boolean — allow everyone to register ->registration(true) // Closure — only allow registration if a matching User already exists // (useful for invite-only setups) ->registration(function ( string $provider, SocialiteUserContract $oauthUser, ?Authenticatable $user, ): bool { return $user !== null; }) ``` -------------------------------- ### Run Upgrade Script for Method Name Changes Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md A rector script is provided to automatically update method names. Execute this command to apply the changes. ```bash vendor/bin/upgrade-v2 ``` -------------------------------- ### Create `socialite_users` Table Migration Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt This migration creates the `socialite_users` pivot table, essential for storing socialite user information. It includes a unique constraint on `(provider, provider_id)` and a foreign key to `users`. ```php // Published stub: database/migrations/create_socialite_users_table.php Schema::create('socialite_users', function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate(); $table->string('provider'); $table->string('provider_id'); $table->timestamps(); $table->unique(['provider', 'provider_id']); }); ``` -------------------------------- ### Configure Stateless Authentication Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Enable stateless authentication for an OAuth provider by setting the 'stateless' option to true in your `config/services.php` file. Note that the 'state' parameter cannot be used with stateless authentication. ```php 'apple' => [ 'client_id' => '...', 'client_secret' => '...', 'stateless'=>true, ] ``` -------------------------------- ### Check Available Routes Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Use this Artisan command to list all routes registered by Filament Socialite in your application. ```bash php artisan route:list --name=socialite ``` -------------------------------- ### Configure Domain Allow List Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Limit OAuth login to users from specific domains by enabling registration and providing a list of allowed domains. ```php ->plugin( FilamentSocialitePlugin::make() // ... ->registration(true) ->domainAllowList(['localhost']) ); ``` -------------------------------- ### Implement Custom Authorization Logic Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Replace the default domain allow-list check with your own authorization logic by providing a closure to `authorizeUserUsing`. The callback must return a boolean value. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; FilamentSocialitePlugin::make() ->authorizeUserUsing(function ( FilamentSocialitePlugin $plugin, SocialiteUserContract $oauthUser, ): bool { // Custom check: must be in domain list AND have a verified email $domainOk = FilamentSocialitePlugin::checkDomainAllowList($plugin, $oauthUser); $emailVerified = $oauthUser->user['email_verified'] ?? false; return $domainOk && $emailVerified; }) ->domainAllowList(['acme.com']); ``` -------------------------------- ### Implement Custom User Authorization Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Define custom logic to authorize users before they can access the application. The default implementation checks the user's email domain against the allow list. Ensure necessary imports are included. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; ->plugin( FilamentSocialitePlugin::make() // ... ->authorizeUserUsing(function (FilamentSocialitePlugin $plugin, SocialiteUserContract $oauthUser) { // Logic to authorize the user. return FilamentSocialitePlugin::checkDomainAllowList($plugin, $oauthUser); }) // ... ); ``` -------------------------------- ### Specify Socialite User Model Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Configure the package to use a custom model for storing Socialite user information by implementing the `FilamentSocialiteUser` interface. ```php // app/Providers/Filament/AdminPanelProvider.php ->plugins([ FilamentSocialitePlugin::make() // ... ->socialiteUserModelClass(\App\Models\SocialiteUser::class) ``` ```php namespace App\Models; use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract; use Illuminate\Contracts\Auth\Authenticatable; use Laravel\Socialite\Contracts\User as SocialiteUserContract; class SocialiteUser implements FilamentSocialiteUserContract { public function getUser(): Authenticatable { // } public static function findForProvider(string $provider, SocialiteUserContract $oauthUser): ?self { // } public static function createForProvider( string $provider, SocialiteUserContract $oauthUser, Authenticatable $user ): self { // } } ``` -------------------------------- ### Define Custom User Creation Logic Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Override the default user creation process when a new OAuth user registers. The default implementation creates a user with only `name` and `email`. Your closure should return an `Authenticatable` instance. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; use App\Models\User; FilamentSocialitePlugin::make() ->createUserUsing(function ( string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin, ): User { return User::create([ 'name' => $oauthUser->getName(), 'email' => $oauthUser->getEmail(), 'avatar_url' => $oauthUser->getAvatar(), 'email_verified_at' => now(), // OAuth email is pre-verified 'password' => null, ]); }); ``` -------------------------------- ### Register Filament Socialite Plugin in AdminPanelProvider Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Register the Filament Socialite plugin in your `AdminPanelProvider.php` file. Configure required providers and optional settings like registration, user model, and slug. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; use Filament\Support\Colors; use Laravel\Socialite\Contracts\User as SocialiteUserContract; use Illuminate\Contracts\Auth\Authenticatable; // ... ->plugin( FilamentSocialitePlugin::make() // (required) Add providers corresponding with providers in `config/services.php`. ->providers([ // Create a provider 'gitlab' corresponding to the Socialite driver with the same name. Provider::make('gitlab') ->label('GitLab') ->icon('fab-gitlab') ->color(Color::hex('#2f2a6b')) ->outlined(false) ->stateless(false) ->scopes(['...']) ->with(['...']) ]) // (optional) Override the panel slug to be used in the oauth routes. Defaults to the panel's configured path. ->slug('admin') // (optional) Enable/disable registration of new (socialite-) users. ->registration(true) // (optional) Enable/disable registration of new (socialite-) users using a callback. // In this example, a login flow can only continue if there exists a user (Authenticatable) already. ->registration(fn (string $provider, SocialiteUserContract $oauthUser, ?Authenticatable $user) => (bool) $user) // (optional) Change the associated model class. ->userModelClass(\App\Models\User::class) // (optional) Change the associated socialite class (see below). ->socialiteUserModelClass(\App\Models\SocialiteUser::class) ); ``` -------------------------------- ### Laravel Services Configuration for GitLab Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Provide the necessary client ID, client secret, and redirect URI for the GitLab OAuth provider in your Laravel application's services configuration file. ```php 'gitlab' => [ 'client_id' => env('GITLAB_CLIENT_ID'), 'client_secret' => env('GITLAB_CLIENT_SECRET'), 'redirect' => env('GITLAB_REDIRECT_URI'), ], ``` -------------------------------- ### Listen to OAuth Events Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Handle various events dispatched during the OAuth flow, such as invalid states, successful logins, new user registrations, provider connections, and blocked registrations. ```php use DutchCodingCompany\FilamentSocialite\Events; use Illuminate\Support\Facades\Event; // In AppServiceProvider::boot() or a dedicated listener class: // Fired when the OAuth state is invalid (potential CSRF) Event::listen(Events\InvalidState::class, function (Events\InvalidState $event) { logger()->warning('Invalid OAuth state', ['exception' => $event->exception->getMessage()]); }); // Fired on every successful login Event::listen(Events\Login::class, function (Events\Login $event) { $user = $event->socialiteUser->getUser(); logger()->info("User {$user->email} logged in via OAuth", [ 'oauth_email' => $event->oauthUser->getEmail(), ]); }); // Fired when a brand-new user is created + linked via OAuth Event::listen(Events\Registered::class, function (Events\Registered $event) { // $event->provider — e.g. 'github' // $event->oauthUser — the raw Socialite user // $event->socialiteUser — the SocialiteUser model SendWelcomeEmail::dispatch($event->socialiteUser->getUser()); }); // Fired when an existing User gets a new OAuth provider linked Event::listen(Events\SocialiteUserConnected::class, function (Events\SocialiteUserConnected $event) { logger()->info("Provider {$event->provider} connected for user {$event->socialiteUser->getUser()->email}"); }); // Fired when the user's email domain is not in the allow list Event::listen(Events\UserNotAllowed::class, function (Events\UserNotAllowed $event) { logger()->warning('OAuth login blocked', ['email' => $event->oauthUser->getEmail()]); }); // Fired when registration is disabled and no existing user is found Event::listen(Events\RegistrationNotEnabled::class, function (Events\RegistrationNotEnabled $event) { logger()->notice("Registration not enabled for provider {$event->provider}", [ 'email' => $event->oauthUser->getEmail(), ]); }); ``` -------------------------------- ### Add Scopes to OAuth Provider Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Configure specific scopes for an OAuth provider like GitHub to request additional permissions. Ensure the scopes are valid for the chosen provider. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; FilamentSocialitePlugin::make() ->providers([ Provider::make('github') ->label('Github') ->icon('fab-github') ->scopes([ // Add scopes here. 'read:user', 'public_repo', ]), ]), ``` -------------------------------- ### Conditionally Show/Hide OAuth Providers Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Use `visible()` and `hidden()` methods on `Provider` instances to conditionally render OAuth buttons. Hidden providers remain functional but their buttons are not displayed. ```php use DutchCodingCompany\FilamentSocialite\Provider; Provider::make('github') ->label('GitHub') ->visible(fn () => config('services.github.client_id') !== null), Provider::make('internal-sso') ->label('Company SSO') ->hidden(fn () => ! app()->environment('production')), ``` -------------------------------- ### Register Filament Socialite Plugin with Providers Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Register the FilamentSocialitePlugin in your admin panel provider. Configure multiple OAuth providers using the Provider builder, and set options like registration, domain allow-list, and login behavior. ```php // app/Providers/Filament/AdminPanelProvider.php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; use Filament\Support\Colors\Color; ->plugin( FilamentSocialitePlugin::make() ->providers([ Provider::make('github') ->label('GitHub') ->icon('fab-github') ->color(Color::hex('#24292e')) ->outlined(true), Provider::make('google') ->label('Google') ->icon('fab-google') ->color(Color::hex('#4285F4')) ->outlined(false), ]) ->registration(true) // allow new users to register via OAuth ->domainAllowList(['acme.com']) // restrict to a single email domain ->slug('admin') // override the URL slug (default: panel path) ->rememberLogin(true) // pass "remember me" to the guard login ->showDivider(true) // show "Or log in via" divider above buttons ) ``` -------------------------------- ### Access Filament Socialite Plugin Instance Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Retrieve the active plugin instance within Filament panels to access its configuration and methods. Useful in event listeners or service classes. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; // Anywhere after the panel has been booted (e.g. inside a listener): $plugin = FilamentSocialitePlugin::current(); $providers = $plugin->getProviders(); // array $domainList = $plugin->getDomainAllowList(); // array $registration = $plugin->getRegistration(); // bool|Closure $panel = $plugin->getPanel(); // Filament\Panel $guard = $plugin->getGuard(); // StatefulGuard ``` -------------------------------- ### Customize Post-Login Redirect Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Use `redirectAfterLoginUsing` to define a custom redirect response after a successful OAuth login. This allows for conditional redirects based on user roles or other criteria. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser; use Illuminate\Http\RedirectResponse; FilamentSocialitePlugin::make() ->redirectAfterLoginUsing(function ( string $provider, FilamentSocialiteUser $socialiteUser, FilamentSocialitePlugin $plugin, ): RedirectResponse { $user = $socialiteUser->getUser(); // Redirect admins to a special dashboard if ($user->hasRole('super_admin')) { return redirect()->route('filament.admin.pages.super-dashboard'); } return redirect()->intended($plugin->getPanel()->getUrl()); }); ``` -------------------------------- ### Set OAuth Provider Visibility Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Control the rendering of OAuth provider buttons in the Filament panel by setting their visibility. Setting `visible(false)` hides the button but keeps the functionality enabled. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; FilamentSocialitePlugin::make() ->providers([ Provider::make('github') ->visible(fn () => true), ]), ``` -------------------------------- ### Implement Custom User Resolution Logic Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Customize how an existing `Authenticatable` user is found when an OAuth user has no linked `socialite_users` record. The default behavior is to search by email address. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use Laravel\Socialite\Contracts\User as SocialiteUserContract; use App\Models\User; FilamentSocialitePlugin::make() ->resolveUserUsing(function ( string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin, ): ?User { // For GitHub, try matching by nickname first, then fall back to email return User::where('github_username', $oauthUser->getNickname())->first() ?? User::where('email', $oauthUser->getEmail())->first(); }); ``` -------------------------------- ### Customize Login Redirect Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Modify the post-login redirect behavior, especially when multi-tenancy is enabled. This method allows you to specify a custom redirect path based on the provider, socialite user, and plugin instance. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract; use DutchCodingCompany\FilamentSocialite\Models\SocialiteUser; FilamentSocialitePlugin::make() ->redirectAfterLoginUsing(function (string $provider, FilamentSocialiteUserContract $socialiteUser, FilamentSocialitePlugin $plugin) { // Change the redirect behaviour here. }); ``` -------------------------------- ### Define Custom SocialiteUser Model Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Replace the default `SocialiteUser` model with a custom implementation by using `socialiteUserModelClass`. The custom model must implement the `FilamentSocialiteUser` contract. ```php // app/Models/SocialiteUser.php namespace App\Models; use DutchCodingCompany\FilamentSocialite\Models\Contracts\FilamentSocialiteUser as FilamentSocialiteUserContract; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Database\Eloquent\Model; use Laravel\Socialite\Contracts\User as SocialiteUserContract; class SocialiteUser extends Model implements FilamentSocialiteUserContract { protected $fillable = ['user_id', 'provider', 'provider_id', 'provider_token']; public function getUser(): Authenticatable { return $this->belongsTo(\App\Models\User::class)->getResults(); } public static function findForProvider(string $provider, SocialiteUserContract $oauthUser): ?static { return static::query() ->where('provider', $provider) ->where('provider_id', $oauthUser->getId()) ->first(); } public static function createForProvider( string $provider, SocialiteUserContract $oauthUser, Authenticatable $user, ): static { return static::query()->create([ 'user_id' => $user->getKey(), 'provider' => $provider, 'provider_id' => $oauthUser->getId(), 'provider_token' => $oauthUser->token, // store access token ]); } } // Register in the panel provider: FilamentSocialitePlugin::make() ->socialiteUserModelClass(\App\Models\SocialiteUser::class); ``` -------------------------------- ### Override Callback URL Slug Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/UPGRADE.md To revert to the previous behavior of using the panel's ID for callback URLs instead of its configured path, use the `slug()` method. ```php ->plugin( FilamentSocialitePlugin::make() ->slug('admin') // change this to the panel's ID // other config for plugin ) ``` -------------------------------- ### Add Optional Parameters to OAuth Provider Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Include optional parameters in the OAuth request, such as the 'hd' parameter for Google, to customize the authentication flow. Refer to Laravel Socialite documentation for available parameters. ```php use DutchCodingCompany\FilamentSocialite\FilamentSocialitePlugin; use DutchCodingCompany\FilamentSocialite\Provider; FilamentSocialitePlugin::make() ->providers([ Provider::make('github') ->label('Github') ->icon('fab-github') ->with([ // Add scopes here. // Add optional parameters here. 'hd' => 'example.com', ]), ]), ``` -------------------------------- ### Specify Custom Authenticatable Model Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Use `userModelClass` to specify a custom authenticatable model class, overriding the default ` App Models User` used by built-in callbacks. ```php FilamentSocialitePlugin::make() ->userModelClass(\App\Models\Admin::class); ``` -------------------------------- ### Make Password Nullable in User Model Source: https://github.com/dutchcodingcompany/filament-socialite/blob/main/README.md Ensure the 'password' attribute on your User model is nullable to support account creation via social login. ```php $table->string('password')->nullable(); ``` -------------------------------- ### Hide Login Form Divider Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Control the visibility of the horizontal divider between the standard login form and OAuth buttons using `showDivider(false)`. This hides the divider, showing only OAuth buttons. ```php FilamentSocialitePlugin::make() ->providers([...]) ->showDivider(false); // hide divider — only OAuth buttons will appear ``` -------------------------------- ### Restrict Logins by Email Domain Source: https://context7.com/dutchcodingcompany/filament-socialite/llms.txt Limit OAuth logins to users with email addresses from specified domains. If the list is empty, all domains are permitted. Users with non-allowed emails will receive an error and trigger a `UserNotAllowed` event. ```php FilamentSocialitePlugin::make() ->providers([...]) ->registration(true) ->domainAllowList(['acme.com', 'acme.org']); // users with @acme.com or @acme.org emails may log in; // all others receive the "user-not-allowed" error and a UserNotAllowed event is fired ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.