{"id":31827940,"url":"https://github.com/chrisreedio/socialment","last_synced_at":"2025-10-11T19:20:48.603Z","repository":{"id":190578586,"uuid":"682933102","full_name":"chrisreedio/socialment","owner":"chrisreedio","description":" Socialite OAuth Support for Filament","archived":false,"fork":false,"pushed_at":"2025-08-20T20:41:08.000Z","size":191,"stargazers_count":100,"open_issues_count":7,"forks_count":14,"subscribers_count":2,"default_branch":"4.x","last_synced_at":"2025-08-20T22:20:48.304Z","etag":null,"topics":["auth","authen","filament","filamentphp","laravel","oauth","oauth2","socialite"],"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/chrisreedio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"chrisreedio"}},"created_at":"2023-08-25T07:47:16.000Z","updated_at":"2025-08-20T20:41:11.000Z","dependencies_parsed_at":"2023-09-26T00:49:41.306Z","dependency_job_id":"bc86e956-8b71-48ba-9bcf-22e3984577ec","html_url":"https://github.com/chrisreedio/socialment","commit_stats":null,"previous_names":["chrisreedio/socialment"],"tags_count":20,"template":false,"template_full_name":"filamentphp/plugin-skeleton","purl":"pkg:github/chrisreedio/socialment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisreedio%2Fsocialment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisreedio%2Fsocialment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisreedio%2Fsocialment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisreedio%2Fsocialment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrisreedio","download_url":"https://codeload.github.com/chrisreedio/socialment/tar.gz/refs/heads/4.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrisreedio%2Fsocialment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008466,"owners_count":26084460,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["auth","authen","filament","filamentphp","laravel","oauth","oauth2","socialite"],"created_at":"2025-10-11T19:20:47.263Z","updated_at":"2025-10-11T19:20:48.595Z","avatar_url":"https://github.com/chrisreedio.png","language":"PHP","funding_links":["https://github.com/sponsors/chrisreedio"],"categories":[],"sub_categories":[],"readme":"# Socialment - Socialite OAuth Support for Filament\n\n![Socialment](https://github.com/chrisreedio/socialment/assets/77644584/53dd1b45-d775-4335-a7ec-ae18456bcab4)\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/chrisreedio/socialment.svg?style=flat-square)](https://packagist.org/packages/chrisreedio/socialment)\n![Tests Action Status](https://github.com/chrisreedio/socialment/actions/workflows/run-tests.yml/badge.svg)\n![Code Style Action Status](https://github.com/chrisreedio/socialment/actions/workflows/fix-php-code-styling.yml/badge.svg)\n![PHPStan Action Status](https://github.com/chrisreedio/socialment/actions/workflows/phpstan.yml/badge.svg)\n[![Total Downloads](https://img.shields.io/packagist/dt/chrisreedio/socialment.svg?style=flat-square)](https://packagist.org/packages/chrisreedio/socialment)\n\n## Table of Contents\n\n- [About](#about)\n- [Installation](#installation)\n- [Basic Setup](#basic-setup)\n- [Provider Configuration](#provider-configuration)\n- [Advanced Configuration](#advanced-configuration)\n- [Customization](#customization)\n- [SPA Authentication](#spa-authentication)\n- [Testing](#testing)\n- [Contributing](#contributing)\n\n---\n\n## About\n\nBring up-to-date and simple Socialite support to your Filament admin panel with this plugin. Adds OAuth buttons to your login page.\n\n**✨ Key Features:**\n- 🔐 Easy OAuth integration with Filament panels\n- 🎨 Customizable provider buttons with icons\n- 🔗 Supports all Laravel Socialite providers\n- 🎯 Per-panel provider configuration  \n- 🔧 Extensible with custom login hooks\n- 📱 Experimental SPA authentication support\n\n**Perfect for:** Laravel and Filament users seeking straightforward OAuth integration.\n\n\u003e [!WARNING]\n\u003e **Socialment v4 is currently in beta.** Please report any issues you encounter.\n\u003e \n\u003e ⚠️ Caution is advised if you choose to use this package in production.\n\u003e \n\u003e 📋 Socialment v3 support is still available on the [3.x branch](https://github.com/chrisreedio/socialment/tree/3.x).\n\n### Demo\n\n🎮 **Demo Project:** [ChrisReedIO/Socialment-Demo](https://github.com/chrisreedio/socialment-demo)\n\n*Not yet updated to v4.*\n\n![Login Screen Preview](https://github.com/chrisreedio/socialment/assets/77644584/c07c6518-df0b-4143-8826-efa3cbdaa681)\n\n### References\n\nThis package extends [Laravel Socialite](https://laravel.com/docs/master/socialite). Socialite currently supports authentication via Facebook, Twitter, LinkedIn, Google, GitHub, GitLab, and Bitbucket out of the box.\n\n📚 **Useful Links:**\n- [Socialite Documentation](https://laravel.com/docs/master/socialite)\n- [Socialite Providers Community](https://socialiteproviders.com/) - Additional provider packages\n\n---\n\n## Installation\n\nInstall the package via Composer:\n\n```bash\ncomposer require chrisreedio/socialment\n```\n\n## Basic Setup\n\n### 1. Run Installation Command\n\nPerform the initial setup:\n\n```bash\nphp artisan socialment:install\n```\n\n### 2. Add Styling Support\n\nEdit your panel's custom `theme.css` and add:\n\n```css\n@source '../../../../vendor/chrisreedio/socialment/resources';\n```\n\n\u003e [!IMPORTANT]\n\u003e **Don't skip this step!** Without it, the plugin styling won't be applied.\n\u003e\n\u003e If you don't have a custom theme, you should create one before adding the source.\n\u003e\n\u003e To learn more about creating a custom theme, see the [Filament documentation](https://filamentphp.com/docs/4.x/styling/overview#creating-a-custom-theme).\n\n### 3. Panel Configuration\n\nInclude the plugin in your panel configuration:\n\n```php\n// In your PanelProvider (e.g., app/Providers/Filament/AdminPanelProvider.php)\n$panel\n    -\u003eplugins([\n        // ... Other Plugins\n        \\ChrisReedIO\\Socialment\\SocialmentPlugin::make(),        \n    ])\n```\n\n---\n\n## Provider Configuration\n\n### Overview\n\nYou need to configure OAuth providers in two places:\n1. **Laravel Socialite** - Install provider packages and configure credentials\n2. **Socialment** - Register providers with your Filament panel\n\n### Step 1: Install \u0026 Configure Socialite Provider\n\nChoose from [stock providers](https://laravel.com/docs/master/socialite) or [community providers](https://socialiteproviders.com/).\n\n**Example: GitHub (Stock Provider)**\n\nAdd to `config/services.php`:\n```php\n'github' =\u003e [\n    'client_id' =\u003e env('GITHUB_CLIENT_ID'),\n    'client_secret' =\u003e env('GITHUB_CLIENT_SECRET'),\n    'redirect' =\u003e env('GITHUB_REDIRECT_URI'),\n],\n```\n\n**Example: Azure Active Directory (Community Provider)**\n\nInstall the provider package:\n```bash\ncomposer require socialiteproviders/microsoft-azure\n```\n\nAdd to `config/services.php`:\n```php\n'azure' =\u003e [    \n    'client_id' =\u003e env('AZURE_CLIENT_ID'),\n    'client_secret' =\u003e env('AZURE_CLIENT_SECRET'),\n    'redirect' =\u003e env('AZURE_REDIRECT_URI'),\n    'tenant' =\u003e env('AZURE_TENANT_ID'),\n    'proxy' =\u003e env('PROXY'), // optional\n],\n```\n\nAdd to `app/Providers/EventServiceProvider.php`:\n```php\nprotected $listen = [\n    // ... other listeners\n    \\SocialiteProviders\\Manager\\SocialiteWasCalled::class =\u003e [\n        // ... other providers\n        \\SocialiteProviders\\Azure\\AzureExtendSocialite::class.'@handle',\n    ],\n];\n```\n\n### Step 2: Register with Socialment\n\nAdd providers to your panel configuration:\n\n```php\n$panel-\u003eplugins([\n    \\ChrisReedIO\\Socialment\\SocialmentPlugin::make()\n        -\u003eregisterProvider('github', 'fab-github', 'GitHub')\n        -\u003eregisterProvider('azure', 'fab-microsoft', 'Azure Active Directory'),\n]);\n```\n\n**Parameters:**\n- `provider_name` - Matches your `config/services.php` key\n- `icon` - Font Awesome brand icon ([search icons](https://fontawesome.com/search?o=r\u0026f=brands))\n- `label` - Display name for the button\n\n### OAuth Redirect URLs\n\n\u003e [!NOTE]\n\u003e **URL Pattern:** `https://yourdomain.com/login/{provider}/callback`\n\u003e \n\u003e **Examples:**\n\u003e - GitHub: `https://yourdomain.com/login/github/callback`  \n\u003e - Azure: `https://yourdomain.com/login/azure/callback`\n\n---\n\n## Advanced Configuration\n\n### Visibility Control\n\nControl when OAuth buttons appear:\n\n```php\n$panel-\u003eplugins([\n    \\ChrisReedIO\\Socialment\\SocialmentPlugin::make()\n        -\u003evisible(fn () =\u003e config('app.env') !== 'production')\n]);\n```\n\n### Custom Login Route\n\nSet a custom route for failed logins:\n\n```php\n$panel-\u003eplugins([\n    \\ChrisReedIO\\Socialment\\SocialmentPlugin::make()\n        -\u003eloginRoute('filament.staff.auth.login')\n        // Or use a closure\n        -\u003eloginRoute(fn () =\u003e SomeFunctionToGetTheRouteName())\n]);\n```\n\n### Login Hooks\n\nAdd custom logic before/after login:\n\n```php\n// In a service provider's boot() method\nuse ChrisReedIO\\Socialment\\Models\\ConnectedAccount;\nuse ChrisReedIO\\Socialment\\Facades\\Socialment;\nuse ChrisReedIO\\Socialment\\Exceptions\\AbortedLoginException;\n\npublic function boot(): void\n{\n    // Pre-login hook\n    Socialment::preLogin(function (ConnectedAccount $connectedAccount) {\n        // Custom pre-login logic here\n        Log::info('User about to login', ['provider' =\u003e $connectedAccount-\u003eprovider]);\n    });\n\n    // Post-login hook\n    Socialment::postLogin(function (ConnectedAccount $connectedAccount) {\n        Log::info('User logged in with ' . $connectedAccount-\u003eprovider . ' account', [\n            'user' =\u003e $connectedAccount-\u003euser-\u003eemail,\n        ]);\n    });\n}\n```\n\n#### Pre-login Hook: External Service Access Control\n\nUse the pre-login hook to verify user access via an external service before allowing authentication:\n\n```php\nuse ChrisReedIO\\Socialment\\Models\\ConnectedAccount;\nuse ChrisReedIO\\Socialment\\Facades\\Socialment;\nuse ChrisReedIO\\Socialment\\Exceptions\\AbortedLoginException;\nuse Illuminate\\Support\\Facades\\Http;\n\npublic function boot(): void\n{\n    // Check to see of the use has sufficient permissions to access the application.\n    Socialment::preLogin(function (ConnectedAccount $connectedAccount) { // Sets up a hook on the 'plugin' itself\n        // Handle custom post login logic here.\n        $groups = (new GraphConnector($connectedAccount-\u003etoken))\n            -\u003eusers()-\u003egroups($connectedAccount-\u003eprovider_user_id);\n\n        // Grab the results from the lazy collection\n        $groupNames = collect($groups-\u003epluck('displayName')-\u003eall());\n\n        // Filter the list of system roles by the groups the user is a member of in Azure AD\n        $roles = Role::all()-\u003efilter(fn ($role) =\u003e $groupNames-\u003econtains($role-\u003esso_group));\n\n        // Sync the user's roles with the filtered list\n        $connectedAccount-\u003euser-\u003eroles()-\u003esync($roles);\n\n        // If the user has no roles, abort the login\n        if ($connectedAccount-\u003euser-\u003eroles-\u003eisEmpty()) {\n            throw new AbortedLoginException('You are not authorized to access this application.');\n        }\n    });\n}\n```\n\n### Configuration File\n\nPublish and customize the config:\n\n```bash\nphp artisan vendor:publish --tag=\"socialment-config\"\n```\n\n**Key config options:**\n```php\nreturn [\n    'view' =\u003e [\n        'prompt' =\u003e 'Or Login Via',  // Text above provider buttons\n        'providers-list' =\u003e 'socialment::providers-list', // Custom view\n    ],\n    \n    'models' =\u003e [\n        'user' =\u003e '\\\\App\\\\Models\\\\User', // Custom user model\n    ],\n];\n```\n\n---\n\n## Customization\n\n### Custom Views\n\nPublish and customize the views:\n\n```bash\nphp artisan vendor:publish --tag=\"socialment-views\"\n```\n\nViews will be copied to `resources/views/vendor/socialment/`.\n\n### Font Awesome Icons\n\nThis package uses [Blade Font Awesome](https://github.com/owenvoke/blade-fontawesome) by [Owen Voke](https://github.com/owenvoke).\n\nSearch for brand icons on the [Font Awesome Website](https://fontawesome.com/search?o=r\u0026f=brands).\n\n---\n\n## SPA Authentication\n\n\u003e [!CAUTION]\n\u003e **🧪 Experimental Feature**\n\u003e \n\u003e This feature is still in development and highly experimental. Expect breaking changes and bugs. Use at your own risk.\n\u003e \n\u003e This feature may be spun off into a separate package in the future.\n\n### Overview\n\nEnable shared authentication between your Filament backend and Single Page Application frontend. Both must be hosted on the same domain.\n\n### Setup Steps\n\n**1. Add SPA routes** to `routes/web.php`:\n```php\n// Pass your SPA route prefix (default: 'spa')\nRoute::spaAuth('dashboard');\n\nRoute::middleware('auth:sanctum')\n    -\u003eprefix('dashboard')\n    -\u003eas('dashboard.')\n    -\u003egroup(function () {\n        // Your SPA API routes\n    });\n```\n\n**2. Update CORS configuration** in `config/cors.php`:\n```php\n'paths' =\u003e [\n    // ... Other Paths\n    'spa/*', // Or your custom prefix\n],\n\n'supports_credentials' =\u003e true,\n```\n\n**3. Set environment variables:**\n```dotenv\nSANCTUM_STATEFUL_DOMAINS=\"https://frontend.localhost:3000,https://backend.localhost\"\nSESSION_DOMAIN=\".localhost\"\nSESSION_SECURE_COOKIE=true\nSPA_URL=\"https://frontend.localhost:3000\"\n```\n\n**Key points:**\n- `SESSION_DOMAIN` should start with a period (`.localhost`)\n- `SPA_URL` points to your frontend application\n- Both frontend and backend must share the same root domain\n\n### SPA Configuration\n\nUpdate the config file:\n```php\n'spa' =\u003e [\n    'home' =\u003e env('SPA_URL', 'http://localhost:3000'),\n    'responses' =\u003e [\n        // Custom JsonResource for API responses\n        // 'me' =\u003e \\App\\Http\\Resources\\UserResponse::class,\n    ],\n],\n```\n\n---\n\n## Testing\n\n\u003e [!NOTE]\n\u003e Tests have yet to be written for this package. They are on the TODO list. PRs welcome!\n\n```bash\ncomposer test\n```\n\n---\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/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\n- [Chris Reed](https://github.com/chrisreedio)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisreedio%2Fsocialment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrisreedio%2Fsocialment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrisreedio%2Fsocialment/lists"}