{"id":40017097,"url":"https://github.com/tharangakothalawala/sso","last_synced_at":"2026-01-19T03:05:35.442Z","repository":{"id":54490265,"uuid":"163588304","full_name":"tharangakothalawala/sso","owner":"tharangakothalawala","description":"This is a library which can provision new accounts and can authenticate users utilizing third party vendor connections.","archived":false,"fork":false,"pushed_at":"2021-02-15T23:07:18.000Z","size":410,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-13T16:49:22.719Z","etag":null,"topics":["authentication","login","provision","register","signin","signup","single-sign-on","single-sign-out","sso"],"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/tharangakothalawala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-30T13:12:58.000Z","updated_at":"2023-09-16T21:13:46.000Z","dependencies_parsed_at":"2022-08-13T17:31:24.666Z","dependency_job_id":null,"html_url":"https://github.com/tharangakothalawala/sso","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tharangakothalawala/sso","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tharangakothalawala%2Fsso","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tharangakothalawala%2Fsso/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tharangakothalawala%2Fsso/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tharangakothalawala%2Fsso/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tharangakothalawala","download_url":"https://codeload.github.com/tharangakothalawala/sso/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tharangakothalawala%2Fsso/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28559378,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T00:46:33.223Z","status":"online","status_checked_at":"2026-01-19T02:00:08.049Z","response_time":67,"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":["authentication","login","provision","register","signin","signup","single-sign-on","single-sign-out","sso"],"created_at":"2026-01-19T03:05:35.287Z","updated_at":"2026-01-19T03:05:35.420Z","avatar_url":"https://github.com/tharangakothalawala.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSK Single Sign On\nThis is a library which can provision new accounts and can authenticate users utilizing third party vendor connections.\n\n[![Latest Stable Version](https://poser.pugx.org/tharangakothalawala/sso/v/stable.svg)](https://packagist.org/packages/tharangakothalawala/sso)\n[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/tharangakothalawala/sso)\n[![Build Status](https://travis-ci.org/tharangakothalawala/sso.svg?branch=master)](https://travis-ci.org/tharangakothalawala/sso)\n[![Quality Score](https://img.shields.io/scrutinizer/g/tharangakothalawala/sso.svg?style=flat-square)](https://scrutinizer-ci.com/g/tharangakothalawala/sso)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/tharangakothalawala/sso.svg?style=flat-square)](https://scrutinizer-ci.com/g/tharangakothalawala/sso)\n[![Total Downloads](https://poser.pugx.org/tharangakothalawala/sso/d/total.svg)](https://packagist.org/packages/tharangakothalawala/sso)\n\n# Supported Vendors\n\n* Amazon\n* Facebook\n* GitHub\n* Google\n* LinkedIn\n* Slack\n* Spotify\n* Stripe\n* Twitter\n* Yahoo\n* Zoom\n\n# Structure\n\nThere are three(3) main functions.\n\n * Third Party Login action\n * Authentication process\n * Revoking access to your client application\n\n## Third Party Login action\n\nUse the following code to redirect a user to the vendor's login page. The following uses Google as an example.\n\n```php\nuse TSK\\SSO\\ThirdParty\\Google\\GoogleConnectionFactory;\n\n$googleConnectionFactory = new GoogleConnectionFactory();\n$googleConnection = $googleConnectionFactory-\u003eget(\n    'google_client_id',\n    'google_client_secret',\n    'http://www.your-amazing-app.com/sso/google/grant'\n);\n\nheader(\"Location: $googleConnection-\u003egetGrantUrl()\");\n```\n\n## Authentication process\n\nUse the following code to do a signup/signin. The following uses Google as an example. Please note that you will have to implement the `TSK\\SSO\\AppUser\\AppUserRepository` to provision and validate users according to your application logic.\nSee my example in the `examples` directory.\n\n#### DefaultAuthenticator Usage\n\n```php\nuse TSK\\SSO\\Auth\\DefaultAuthenticator;\nuse TSK\\SSO\\Auth\\Exception\\AuthenticationFailedException;\nuse TSK\\SSO\\ThirdParty\\Exception\\NoThirdPartyEmailFoundException;\nuse TSK\\SSO\\ThirdParty\\Exception\\ThirdPartyConnectionFailedException;\nuse TSK\\SSO\\ThirdParty\\Google\\GoogleConnectionFactory;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$googleConnectionFactory = new GoogleConnectionFactory();\n$googleConnection = $googleConnectionFactory-\u003eget(\n    'google_client_id',\n    'google_client_secret',\n    'http://www.your-amazing-app.com/sso/google/grant'\n);\n\n$authenticator = new DefaultAuthenticator(\n    new YourImplementationOfTheAppUserRepository()\n);\n\ntry {\n    $appUser = $authenticator-\u003eauthenticate($googleConnection);\n} catch (AuthenticationFailedException $ex) {\n} catch (DataCannotBeStoredException $ex) {\n} catch (NoThirdPartyEmailFoundException $ex) {\n} catch (ThirdPartyConnectionFailedException $ex) {\n} catch (\\Exception $ex) {\n}\n\n// log the detected application's user in\n$_SESSION['userId'] = $appUser-\u003eid();\n```\n\nPlease note that using the `TSK\\SSO\\Auth\\DefaultAuthenticator` will just do a simple lookup of the user store using your logic. If you want to support multiple vendors and to avoid creating new users per each of their specific email address, you will have to use this `TSK\\SSO\\Auth\\PersistingAuthenticator`.\n\n#### PersistingAuthenticator Usage\n\nThis uses File System by default as the storage for the user mappings.\n\n```php\nuse TSK\\SSO\\Auth\\PersistingAuthenticator;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$authenticator = new PersistingAuthenticator(\n    new YourImplementationOfTheAppUserRepository()\n);\n```\n\n##### MySQL\n\nThere are two classes available for you to use MySQL as the storage.\n\nFor MySQL, I have provided a schema file under sql folder. Please use that.\n\n* `TSK\\SSO\\Storage\\PdoThirdPartyStorageRepository`\n\n```php\nuse TSK\\SSO\\Auth\\PersistingAuthenticator;\nuse TSK\\SSO\\Storage\\PdoThirdPartyStorageRepository;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$authenticator = new PersistingAuthenticator(\n    new YourImplementationOfTheAppUserRepository(),\n    new PdoThirdPartyStorageRepository(\n        // In Laravel, you can do this to get its PDO connection: \\DB::connection()-\u003egetPdo();\n        new PDO('mysql:dbname=db;host=localhost', 'foo', 'bar'),\n        'Optional Table Name (default:thirdparty_connections)'\n    ),\n);\n```\n\n* `TSK\\SSO\\Storage\\MysqliThirdPartyStorageRepository`\n\n```php\nuse TSK\\SSO\\Auth\\PersistingAuthenticator;\nuse TSK\\SSO\\Storage\\PdoThirdPartyStorageRepository;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$authenticator = new PersistingAuthenticator(\n    new YourImplementationOfTheAppUserRepository(),\n    new MysqliThirdPartyStorageRepository(new mysqli('localhost', 'foo', 'bar', 'db')),\n);\n```\n\n##### MongoDB\n\n* `TSK\\SSO\\Storage\\PeclMongoDbThirdPartyStorageRepository`\n\n```php\nuse TSK\\SSO\\Auth\\PersistingAuthenticator;\nuse TSK\\SSO\\Storage\\PeclMongoDbThirdPartyStorageRepository;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$authenticator = new PersistingAuthenticator(\n    new YourImplementationOfTheAppUserRepository(),\n    new PeclMongoDbThirdPartyStorageRepository(new MongoDB\\Driver\\Manager('mongodb://localhost:27017/yourdb'), 'yourdb'),\n);\n```\n\nOf course you can use your own storage by just implementing this interface : `TSK\\SSO\\Storage\\ThirdPartyStorageRepository`.\n\n## Revoking vendor access to your client application\n\n```php\nuse TSK\\SSO\\ThirdParty\\VendorConnectionRevoker;\n\n$vendorConnectionRevoker = new VendorConnectionRevoker(\n    $googleConnection, // the vendor connection\n    // [optional] `TSK\\SSO\\Storage\\ThirdPartyStorageRepository` implementation. File system storage is used by default\n);\n$vendorConnectionRevoker-\u003erevoke($vendorEmail, $vendorName); // returns a bool\n```\n\n## Connecting multiple accounts while logged in.\n\n * A user may have multiple accounts on one(1) vendor.\nex: Multiple Facebook/Google accounts with different email addresses.\n\n * Or a user can have accounts on other vendors such as Facebook and Google at the same time. You may want to let them connect other accounts to make it easier for them to authenticate/access using multiple vendors.\n\nYou can use the `TSK\\SSO\\Auth\\AppUserAwarePersistingAuthenticator` to validate the account that they selecting.\n\n```php\nuse TSK\\SSO\\AppUser\\ExistingAppUser;\nuse TSK\\SSO\\Auth\\AppUserAwarePersistingAuthenticator;\nuse TSK\\SSO\\Auth\\PersistingAuthenticator;\nuse YouApp\\TSKSSO\\YourImplementationOfTheAppUserRepository;\n\n$userId = $_SESSION['userid'];\nif (!is_null($userId)) {\n    $authenticator = new AppUserAwarePersistingAuthenticator(\n        new ExistingAppUser($userId, 'current-loggedin-user-email@tsk-webdevelopment.com')\n    );\n} else {\n    $authenticator = new PersistingAuthenticator(\n        new YourImplementationOfTheAppUserRepository()\n    );\n}\n```\n\n\n# What Next?\n\nTo add any missing vendor support and any other storage systems.\n\n# Demo\n\n#### Creating your own apps [Optional]\n\nI have created several demo apps and have registered them in Amazon, GitHub, Google, Twitter \u0026 Yahoo.\nOptionally you may register your own apps if you want to test.\n\n* Amazon : https://sellercentral.amazon.com/hz/home\n* GitHub : https://github.com/settings/developers\n* Google : https://console.developers.google.com\n* Twitter : https://developer.twitter.com/en/apps - You must at least have 'Read-only' access permission and have ticked 'Request email address from users' under additional permissions.\n* Spotify : https://developer.spotify.com/dashboard/applications\n* Yahoo : https://developer.yahoo.com/apps - You must at least select 'Read/Write Public and Private' of 'Profiles (Social Directory)' API permissions.\n\n#### Host File Entry\n\nAnd add the `localhost.com` into the host file as following. (Linux : `/etc/hosts`, Windows: `C:\\Windows\\System32\\drivers\\etc\\hosts`)\n\n```bash\n127.0.0.1    localhost.com\n```\n\n#### Start Demo\n```bash\nmake demo\n```\n\nThen go to http://localhost.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharangakothalawala%2Fsso","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftharangakothalawala%2Fsso","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftharangakothalawala%2Fsso/lists"}