{"id":13733645,"url":"https://github.com/DutchCodingCompany/filament-socialite","last_synced_at":"2025-05-08T09:32:38.968Z","repository":{"id":37930470,"uuid":"475352040","full_name":"DutchCodingCompany/filament-socialite","owner":"DutchCodingCompany","description":"Add OAuth login through Laravel Socialite to Filament.","archived":false,"fork":false,"pushed_at":"2025-02-25T10:25:39.000Z","size":477,"stargazers_count":180,"open_issues_count":2,"forks_count":43,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-05-04T03:57:49.884Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DutchCodingCompany.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-03-29T08:34:44.000Z","updated_at":"2025-04-22T18:36:25.000Z","dependencies_parsed_at":"2023-12-05T14:27:36.807Z","dependency_job_id":"d79a0be4-8132-4fbf-af84-5334af56994b","html_url":"https://github.com/DutchCodingCompany/filament-socialite","commit_stats":{"total_commits":273,"total_committers":27,"mean_commits":10.11111111111111,"dds":0.717948717948718,"last_synced_commit":"ec4d69cb5b88d3eb9f54d8b977956034a5838a2f"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Ffilament-socialite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Ffilament-socialite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Ffilament-socialite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Ffilament-socialite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DutchCodingCompany","download_url":"https://codeload.github.com/DutchCodingCompany/filament-socialite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253036737,"owners_count":21844269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:46.807Z","updated_at":"2025-05-08T09:32:38.959Z","avatar_url":"https://github.com/DutchCodingCompany.png","language":"PHP","funding_links":[],"categories":["MISC"],"sub_categories":[],"readme":"\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://banners.beyondco.de/Filament%20Socialite.png?theme=dark\u0026packageManager=composer+require\u0026packageName=DutchCodingCompany%2Ffilament-socialite\u0026pattern=architect\u0026style=style_1\u0026description=Add+OAuth+login+through+Laravel+Socialite+to+Filament.\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=user-group\"\u003e\n  \u003cimg src=\"https://banners.beyondco.de/Filament%20Socialite.png?theme=light\u0026packageManager=composer+require\u0026packageName=DutchCodingCompany%2Ffilament-socialite\u0026pattern=architect\u0026style=style_1\u0026description=Add+OAuth+login+through+Laravel+Socialite+to+Filament.\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=user-group\"\u003e\n\u003c/picture\u003e\n\n# Social login for Filament through Laravel Socialite\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/dutchcodingcompany/filament-socialite.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/filament-socialite)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/dutchcodingcompany/filament-socialite/run-tests?label=tests)](https://github.com/dutchcodingcompany/filament-socialite/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/dutchcodingcompany/filament-socialite/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/dutchcodingcompany/filament-socialite/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/dutchcodingcompany/filament-socialite.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/filament-socialite)\n\nAdd OAuth2 login through Laravel Socialite to Filament. OAuth1 (eg. Twitter) is not supported at this time.\n\n## Installation\n\n| Filament version                                                                                                                                               | Package version | Readme                                                                               |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|--------------------------------------------------------------------------------------|\n| [^3.2.44](https://github.com/filamentphp/filament/releases/tag/v3.2.44) (if using [SPA mode](https://filamentphp.com/docs/3.x/panels/configuration#spa-mode))  | 2.x.x           | [Link](https://github.com/DutchCodingCompany/filament-socialite/blob/main/README.md) |\n| [^3.2.44](https://github.com/filamentphp/filament/releases/tag/v3.2.44) (if using [SPA mode](https://filamentphp.com/docs/3.x/panels/configuration#spa-mode))  | ^1.3.1          |                                                                                      |\n| 3.x                                                                                                                                                            | 1.x.x           | [Link](https://github.com/DutchCodingCompany/filament-socialite/blob/1.x/README.md)  |\n| 2.x                                                                                                                                                            | 0.x.x           |                                                                                      |\n\nInstall the package via composer:\n\n```bash\ncomposer require dutchcodingcompany/filament-socialite\n```\n\nPublish and migrate the migration file:\n\n```bash\nphp artisan vendor:publish --tag=\"filament-socialite-migrations\"\nphp artisan migrate\n```\n\nOther configuration files include:\n```bash\nphp artisan vendor:publish --tag=\"filament-socialite-config\"\nphp artisan vendor:publish --tag=\"filament-socialite-views\"\nphp artisan vendor:publish --tag=\"filament-socialite-translations\"\n```\n\nYou need to register the plugin in the Filament panel provider (the default filename is `app/Providers/Filament/AdminPanelProvider.php`). The following options are available:\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse DutchCodingCompany\\FilamentSocialite\\Provider;\nuse Filament\\Support\\Colors;\nuse Laravel\\Socialite\\Contracts\\User as SocialiteUserContract;\nuse Illuminate\\Contracts\\Auth\\Authenticatable;\n\n// ...\n-\u003eplugin(\n    FilamentSocialitePlugin::make()\n        // (required) Add providers corresponding with providers in `config/services.php`. \n        -\u003eproviders([\n            // Create a provider 'gitlab' corresponding to the Socialite driver with the same name.\n            Provider::make('gitlab')\n                -\u003elabel('GitLab')\n                -\u003eicon('fab-gitlab')\n                -\u003ecolor(Color::hex('#2f2a6b'))\n                -\u003eoutlined(false)\n                -\u003estateless(false)\n                -\u003escopes(['...'])\n                -\u003ewith(['...']),\n        ])\n        // (optional) Override the panel slug to be used in the oauth routes. Defaults to the panel ID.\n        -\u003eslug('admin')\n        // (optional) Enable/disable registration of new (socialite-) users.\n        -\u003eregistration(true)\n        // (optional) Enable/disable registration of new (socialite-) users using a callback.\n        // In this example, a login flow can only continue if there exists a user (Authenticatable) already.\n        -\u003eregistration(fn (string $provider, SocialiteUserContract $oauthUser, ?Authenticatable $user) =\u003e (bool) $user)\n        // (optional) Change the associated model class.\n        -\u003euserModelClass(\\App\\Models\\User::class)\n        // (optional) Change the associated socialite class (see below).\n        -\u003esocialiteUserModelClass(\\App\\Models\\SocialiteUser::class)\n);\n```\n\nThis package automatically adds 2 routes per panel to make the OAuth flow possible: a redirector and a callback. When\nsetting up your **external OAuth app configuration**, enter the following callback URL (in this case for the Filament\npanel with ID `admin` and the `github` provider):\n```\nhttps://example.com/admin/oauth/callback/github\n```\n\nA multi-panel callback route is available as well that does not contain the panel ID in the url. Instead, it determines\nthe panel ID from an encrypted `state` input (`...?state=abcd1234`). This allows you to create a single OAuth\napplication for multiple Filament panels that use the same callback URL. Note that this only works for _stateful_ OAuth\napps:\n\n```\nhttps://example.com/oauth/callback/github\n```\n\nIf in doubt, run `php artisan route:list` to see which routes are available to you.\n\n### CSRF protection\n_(Only applicable to Laravel 10.x users can ignore this section)_\n\nIf your third-party provider calls the OAuth callback using a `POST` request, you need to add the callback route to the\nexception list in your `VerifyCsrfToken` middleware. This can be done by adding the url to the `$except` array:\n\n```php\nprotected $except = [\n    '*/oauth/callback/*',\n    'oauth/callback/*',\n];\n````\n\nFor Laravel 11.x (or newer) users, this exception is automatically added by our service provider.\n\nSee [Socialite Providers](https://socialiteproviders.com/) for additional Socialite providers.\n\n### Icons\n\nYou can specify a custom icon for each of your login providers. You can add Font Awesome brand\nicons made available through [Blade Font Awesome](https://github.com/owenvoke/blade-fontawesome) by running:\n```bash\ncomposer require owenvoke/blade-fontawesome\n```\n\n### Registration flow\n\nThis package supports account creation for users. However, to support this flow it is important that the `password`\nattribute on your `User` model is nullable. For example, by adding the following to your users table migration.\nOr you could opt for customizing the user creation, see below.\n\n```php\n$table-\u003estring('password')-\u003enullable();\n```\n\n### Domain Allow list\n\nThis package supports the option to limit the users that can login with the OAuth login to users of a certain domain.\nThis can be used to setup SSO for internal use.\n\n```php\n-\u003eplugin(\n    FilamentSocialitePlugin::make()\n        // ...\n        -\u003eregistration(true)\n        -\u003edomainAllowList(['localhost'])\n);\n```\n\n### Changing how an Authenticatable user is created or retrieved\n\nYou can use the `createUserUsing` and `resolveUserUsing` methods to change how a user is created or retrieved.\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse Laravel\\Socialite\\Contracts\\User as SocialiteUserContract;\n\n-\u003eplugin(\n    FilamentSocialitePlugin::make()\n        // ...\n        -\u003ecreateUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) {\n            // Logic to create a new user.\n        })\n        -\u003eresolveUserUsing(function (string $provider, SocialiteUserContract $oauthUser, FilamentSocialitePlugin $plugin) {\n            // Logic to retrieve an existing user.\n        })\n        ...\n);\n```\n\n### Change how a Socialite user is created or retrieved\n\nIn your plugin options in your Filament panel, add the following method:\n\n```php\n// app/Providers/Filament/AdminPanelProvider.php\n-\u003eplugins([\n    FilamentSocialitePlugin::make()\n        // ...\n        -\u003esocialiteUserModelClass(\\App\\Models\\SocialiteUser::class)\n```\n\nThis class should at the minimum implement the [`FilamentSocialiteUser`](/src/Models/Contracts/FilamentSocialiteUser.php) interface, like so:\n\n```php\nnamespace App\\Models;\n\nuse DutchCodingCompany\\FilamentSocialite\\Models\\Contracts\\FilamentSocialiteUser as FilamentSocialiteUserContract;\nuse Illuminate\\Contracts\\Auth\\Authenticatable;\nuse Laravel\\Socialite\\Contracts\\User as SocialiteUserContract;\n\nclass SocialiteUser implements FilamentSocialiteUserContract\n{\n    public function getUser(): Authenticatable\n    {\n        //\n    }\n\n    public static function findForProvider(string $provider, SocialiteUserContract $oauthUser): ?self\n    {\n        //\n    }\n    \n    public static function createForProvider(\n        string $provider,\n        SocialiteUserContract $oauthUser,\n        Authenticatable $user\n    ): self {\n        //\n    }\n}\n```\n\n### Check if the user is authorized to use the application\n\nYou can use the `authorizeUserUsing` method to check if the user is authorized to use the application. **Note:** by [default](/src/Traits/Callbacks.php#L145) this method check if the user's email domain is in the domain allow list.\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse Laravel\\Socialite\\Contracts\\User as SocialiteUserContract;\n\n-\u003eplugin(\n    FilamentSocialitePlugin::make()\n        // ...\n        -\u003eauthorizeUserUsing(function (FilamentSocialitePlugin $plugin, SocialiteUserContract $oauthUser) {\n            // Logic to authorize the user.\n            return FilamentSocialitePlugin::checkDomainAllowList($plugin, $oauthUser);\n        })\n        // ...\n);\n```\n\n### Change login redirect\n\nWhen your panel has [multi-tenancy](https://filamentphp.com/docs/3.x/panels/tenancy) enabled, after logging in, the user will be redirected to their [default tenant](https://filamentphp.com/docs/3.x/panels/tenancy#setting-the-default-tenant).\nIf you want to change this behavior, you can call the 'redirectAfterLoginUsing' method on the `FilamentSocialitePlugin`.\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse DutchCodingCompany\\FilamentSocialite\\Models\\Contracts\\FilamentSocialiteUser as FilamentSocialiteUserContract;\nuse DutchCodingCompany\\FilamentSocialite\\Models\\SocialiteUser;\n\nFilamentSocialitePlugin::make()\n    -\u003eredirectAfterLoginUsing(function (string $provider, FilamentSocialiteUserContract $socialiteUser, FilamentSocialitePlugin $plugin) {\n        // Change the redirect behaviour here.\n    });\n```\n\n### Filament Fortify\n\nThis component can also be added while using the [Fortify plugin](https://filamentphp.com/plugins/fortify) plugin.\n\n```php\n## in Service Provider file\npublic function boot()\n{\n    //...\n    \n    Filament::registerRenderHook(\n        'filament-fortify.login.end',\n        fn (): string =\u003e Blade::render('\u003cx-filament-socialite::buttons /\u003e'),\n    );\n}\n```\n\n### Filament Breezy\n\nThis component can also be added while using the [Breezy plugin](https://filamentphp.com/plugins/jeffgreco-breezy) plugin.\n\nYou can publish the login page for **Filament Breezy** by running:\n\n```bash\nphp artisan vendor:publish --tag=\"filament-breezy-views\"\n```\n\nWhich produces a login page at `resources/views/vendor/filament-breezy/login.blade.php`.\n\nYou can then add the following snippet in your form:\n\n```html\n\u003cx-filament-socialite::buttons /\u003e\n```\n\n## Events\n\nThere are a few events dispatched during the authentication process:\n\n* `InvalidState(InvalidStateException $exception)`: When trying to retrieve the oauth (socialite) user, an invalid state was encountered\n* `Login(FilamentSocialiteUserContract $socialiteUser)`: When a user successfully logs in\n* `Registered(string $provider, SocialiteUserContract $oauthUser, FilamentSocialiteUserContract $socialiteUser)`: When a user and socialite user is successfully registered and logged in (when enabled in config)\n* `RegistrationNotEnabled(string $provider, SocialiteUserContract $oauthUser, ?Auhthenticatable $user)`: When a user tries to login with an unknown account and registration is not enabled\n* `SocialiteUserConnected(string $provider, SocialiteUserContract $oauthUser, FilamentSocialiteUserContract $socialiteUser)`: When a socialite user is created for an existing user\n* `UserNotAllowed(SocialiteUserContract $oauthUser)`: When a user tries to login with an email which domain is not on the allowlist\n\n## Scopes\n\nScopes can be added to the provider on the panel, for example:\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse DutchCodingCompany\\FilamentSocialite\\Provider;\n\nFilamentSocialitePlugin::make()\n    -\u003eproviders([\n        Provider::make('github')\n            -\u003elabel('Github')\n            -\u003eicon('fab-github')\n            -\u003escopes([\n                // Add scopes here.\n                'read:user',\n                'public_repo',\n            ]),\n    ]),\n```\n\n## Optional parameters\n\nYou can add [optional parameters](https://laravel.com/docs/10.x/socialite#optional-parameters) to the request by adding a `with` key to the provider on the panel, for example:\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse DutchCodingCompany\\FilamentSocialite\\Provider;\n\nFilamentSocialitePlugin::make()\n    -\u003eproviders([\n        Provider::make('github')\n            -\u003elabel('Github')\n            -\u003eicon('fab-github')\n            -\u003ewith([\n                // Add scopes here.\n                // Add optional parameters here.\n                'hd' =\u003e 'example.com',\n            ]),\n    ]),\n```\n## Visibility\n\nYou can set the visibility of a provider, if it is not visible, buttons will not be rendered. All functionality will still be enabled.\n\n```php\nuse DutchCodingCompany\\FilamentSocialite\\FilamentSocialitePlugin;\nuse DutchCodingCompany\\FilamentSocialite\\Provider;\n\nFilamentSocialitePlugin::make()\n    -\u003eproviders([\n        Provider::make('github')\n            -\u003evisible(fn () =\u003e true),\n    ]),\n```\n\n## Stateless Authentication\nYou can add `stateless` parameters to the provider configuration in the config/services.php config file, for example:\n\n```php\n'apple' =\u003e [\n    'client_id' =\u003e '...',\n    'client_secret' =\u003e '...',\n    'stateless'=\u003etrue,\n]\n```\n\n**Note:** you cannot use the `state` parameter, as it is used to determine from which Filament panel the user came from.\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDutchCodingCompany%2Ffilament-socialite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDutchCodingCompany%2Ffilament-socialite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDutchCodingCompany%2Ffilament-socialite/lists"}