{"id":17922678,"url":"https://github.com/overtrue/laravel-saml","last_synced_at":"2025-10-19T21:06:59.246Z","repository":{"id":50271602,"uuid":"402261223","full_name":"overtrue/laravel-saml","owner":"overtrue","description":"SAML toolkit for Laravel based on OneLogin's SAML PHP Toolkit.","archived":false,"fork":false,"pushed_at":"2025-02-08T01:03:25.000Z","size":69,"stargazers_count":22,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-02T06:12:48.128Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/overtrue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["overtrue"]}},"created_at":"2021-09-02T02:12:07.000Z","updated_at":"2025-02-08T01:03:29.000Z","dependencies_parsed_at":"2024-02-17T06:31:05.561Z","dependency_job_id":"6d6e4c59-c7e1-4d0e-aa8c-dcf9df0f8622","html_url":"https://github.com/overtrue/laravel-saml","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.04347826086956519,"last_synced_commit":"722637ed09ed723529f31fcd65dc854969c1a71d"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":"overtrue/laravel-package","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Flaravel-saml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Flaravel-saml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Flaravel-saml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/overtrue%2Flaravel-saml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/overtrue","download_url":"https://codeload.github.com/overtrue/laravel-saml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066179,"owners_count":20392406,"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-10-28T20:40:24.741Z","updated_at":"2025-10-19T21:06:54.211Z","avatar_url":"https://github.com/overtrue.png","language":"PHP","funding_links":["https://github.com/sponsors/overtrue"],"categories":[],"sub_categories":[],"readme":"Laravel SAML\n---\n\nSAML toolkit for Laravel based on [OneLogin's SAML PHP Toolkit](https://github.com/onelogin/php-saml).\n\n[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)\n\n## Installation\n\n```bash\ncomposer require overtrue/laravel-saml\n```\n\n## Configuration\n\n```bash\nphp artisan vendor:publish --tag=saml-config\n```\n\nThis command will add the file `config/saml.php`. This config is handled almost directly by [OneLogin](https://github.com/onelogin/php-saml) so you may get further references there, but will cover here what's really necessary. There are some other config about routes you may want to check, they are pretty straightforward.\n\n## Usage\n\nIf your application is only used to log in to one specified IdP, you just need to configure `idp` section in `config/saml.php`.\n\n### idp configuration resolver\n\nIn order to support multiple IdP, you need to configure the following method to get the configuration of the IdP.\n\n```php\nSaml::configureIdpUsing(function($idpName): array {\n    return [...]; \n});\n```\n\nYou need to return the configuration array for IdP, see the `idp` section in `config/saml.php` for the structure.\n\n### Entrypoints controller\n\nYou can create a controller to perform SAML integration:\n\n```php\n$ php artisan make:controller SamlController\n```\n\nThen we prepare the following 5 necessary methods.\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse Overtrue\\LaravelSaml\\Saml;\n\nclass SamlController extends Controller\n{\n    public function login() {}\n    public function acs() {}\n    public function logout() {}\n    public function sls() {}\n    public function metadata() {}\n}\n```\n\n### Entrypoints Routes\n\nThen configure the routes at `routes/web.php`:\n\n| Method | URI                      | Name \t\t\t\t|\n| -------|--------------------------|------------------ |\n| GET    | `{routesPrefix}/login`     | saml.login \t\t|\n| POST   | `{routesPrefix}/acs`       | saml.acs \t\t\t|\n| GET    | `{routesPrefix}/logout`    | saml.logout \t\t|\n| GET    | `{routesPrefix}/sls`       | saml.sls \t\t\t|\n| GET    | `{routesPrefix}/metadata`  | saml.metadata \t|\n\nYou are free to use your preferred routing prefix, for example, we use `saml` as the routing prefix:\n\n```php\nuse App\\Http\\Controllers\\SamlController;\n\nRoute::get('saml/login', [SamlController::class, 'login'])-\u003ename('saml.login');\nRoute::get('saml/logout', [SamlController::class, 'logout'])-\u003ename('saml.logout');\nRoute::post('saml/acs', [SamlController::class, 'acs'])-\u003ename('saml.acs');\nRoute::get('saml/sls', [SamlController::class, 'sls'])-\u003ename('saml.sls');\nRoute::get('saml/metadata', [SamlController::class, 'metadata'])-\u003ename('saml.metadata');\n```\n\n#### Redirect to IdP login service\n\nInitiates the SSO process, creates an AuthnRequest, returns a laravel redirect response.\n\n```php\n    //\u003c...\u003e\n    public function login(Request $request)\n    {\n        // Use the default idp in the configuration\n        return Saml::redirect(); \n        \n        // Or specify the idp name\n        return Saml::idp($request-\u003eget('idp'))-\u003eredirect();\n    }\n```\n\n#### Assertion Consumer Service (ACS)\n\nThis method is used to handle the IdP authorization callback, `SamlAuth::getAuthenticatedUser` will validation the request and return a `Overtrue\\LaravelSaml\\SamlUser` object.\n\n```php\n//\u003c...\u003e\n    public function acs(Request $request)\n    {\n        // Overtrue\\LaravelSaml\\SamlUser\n        $samlUser = Saml::getAuthenticatedUser();\n        // Or specify the idp name\n        //$samlUser = Saml::idp($request-\u003eget('idp'))-\u003egetAuthenticatedUser(); \n        \n        $samlUserId = $samlUser-\u003egetNameId();\n        \n        // SamlUser to app User\n        // $user = User::FirstOrCreate(['email' =\u003e $samlUser-\u003egetNameId()]);\n        Auth::set($user);\n        \n        return redirect('/home')\n    }\n```\n\n#### Redirect to IdP logout service\n\nCreate a redirect response to IdP logout service.\n\n```php\n    //\u003c...\u003e\n    public function logout(Request $request)\n    {\n        // Use the default IdP in the configuration\n        return Saml::redirectToLogout(); \n        \n        // Or specify the IdP name\n        return Saml::idp($request-\u003eget('idp'))-\u003eredirectToLogout();\n    }\n```\n\nThe IdP will return the Logout Response through the user's client to the Single Logout Service of the SP (route `saml/sls`).\n\n#### Single Logout Service (SLS)\n\nThis code handles the Logout Request and the Logout Responses.\n\n```php\n    //\u003c...\u003e\n    public function sls(Request $request)\n    {\n        $auth = Saml::handleLogoutRequest();\n        // Or specify the IdP name\n        //$auth = Saml::idp($request-\u003eget('idp'))-\u003ehandleLogoutRequest();\n    \n        Auth::logout();\n        \n        return redirect('/home')\n    }\n```\n\n#### Metadata\n\nThis code will provide the XML metadata file of our SP, based on the info that we provided in the settings files.\n\n```php\n    //\u003c...\u003e\n    public function metadata(Request $request)\n    {\n        if ($request-\u003ehas('download')) {\n            return Saml::getMetadataXMLAsStreamResponse();\n            // or specify a filename to the xml file:\n            // return Saml::getMetadataXMLAsStreamResponse('sp-metadata.xml');\n        }\n        \n        return Saml::getMetadataXML();\n    }\n```\n\n### More\n\nFor more information on configuration and usage please see the source code or read [onelogin/php-saml](https://github.com/onelogin/php-saml).\n\n\n## :heart: Sponsor me \n\n[![Sponsor me](https://github.com/overtrue/overtrue/blob/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)\n\n如果你喜欢我的项目并想支持它，[点击这里 :heart:](https://github.com/sponsors/overtrue)\n\n\n## Project supported by JetBrains\n\nMany thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.\n\n[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/overtrue)\n\n## Contributing\n\nYou can contribute in one of three ways:\n\n1. File bug reports using the [issue tracker](https://github.com/overtrue/laravel-package/issues).\n2. Answer questions or fix bugs on the [issue tracker](https://github.com/overtrue/laravel-package/issues).\n3. Contribute new features or update the wiki.\n\n_The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable._\n\n## PHP 扩展包开发\n\n\u003e 想知道如何从零开始构建 PHP 扩展包？\n\u003e\n\u003e 请关注我的实战课程，我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Flaravel-saml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovertrue%2Flaravel-saml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovertrue%2Flaravel-saml/lists"}