PHPackages                             yuca/sso - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. yuca/sso

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

yuca/sso
========

Simple Single Sign-On

v0.4.2(6y ago)2924[1 PRs](https://github.com/YucaApp/sso/pulls)MITPHPPHP &gt;=5.5.0

Since Sep 27Pushed 2y agoCompare

[ Source](https://github.com/YucaApp/sso)[ Packagist](https://packagist.org/packages/yuca/sso)[ Docs](https://github.com/YucaApp/sso)[ RSS](/packages/yuca-sso/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (3)Versions (19)Used By (0)

Single Sign-On for PHP (Ajax compatible)
----------------------------------------

[](#single-sign-on-for-php-ajax-compatible)

**NOTES**: This version is forked from  which improved with the following features:

- NGINX server support
- Whitelist IP
- Cache &amp; Session 3rd party support

Jasny\\SSO is a relatively simply and straightforward solution for an single sign on (SSO) implementation. With SSO, logging into a single website will authenticate you for all affiliate sites.

#### How it works

[](#how-it-works)

When using SSO, when can distinguish 3 parties:

- Client - This is the browser of the visitor
- Broker - The website which is visited
- Server - The place that holds the user info and credentials

The broker has an id and a secret. These are know to both the broker and server.

When the client visits the broker, it creates a random token, which is stored in a cookie. The broker will then send the client to the server, passing along the broker's id and token. The server creates a hash using the broker id, broker secret and the token. This hash is used to create a link to the users session. When the link is created the server redirects the client back to the broker.

The broker can create the same link hash using the token (from the cookie), the broker id and the broker secret. When doing requests, it passes that has as session id.

The server will notice that the session id is a link and use the linked session. As such, the broker and client are using the same session. When another broker joins in, it will also use the same session.

For a more indepth explanation, please [read this article](https://github.com/jasny/sso/wiki).

#### How is this different from OAuth?

[](#how-is-this-different-from-oauth)

With OAuth, you can authenticate a user at an external server and get access to their profile info. However you aren't sharing a session.

A user logs in to website foo.com using Google OAuth. Next he visits website bar.org which also uses Google OAuth. Regardless of that, he is still required to press on the 'login' button on bar.org.

With Jasny/SSO both websites use the same session. So when the user visits bar.org, he's automatically logged in. When he logs out (on either of the sites), he's logged out for both.

Installation
------------

[](#installation)

Install this library through composer

```
composer require jasny/sso

```

Usage
-----

[](#usage)

#### Server

[](#server)

`Jasny\SSO\Server` is an abstract class. You need to create a your own class which implements the abstract methods. These methods are called fetch data from a data souce (like a DB).

```
class MySSOServer extends Jasny\SSO\Server
{
    /**
     * Authenticate using user credentials
     *
     * @param string $username
     * @param string $password
     * @return \Jasny\ValidationResult
     */
    abstract protected function authenticate($username, $password)
    {
        ...
    }

    /**
     * Get the secret key and other info of a broker
     *
     * @param string $brokerId
     * @return array
     */
    abstract protected function getBrokerInfo($brokerId)
    {
        ...
    }

    /**
     * Get the information about a user
     *
     * @param string $username
     * @return array|object
     */
    abstract protected function getUserInfo($username)
    {
        ...
    }
}
```

The MySSOServer class can be used as controller in an MVC framework.

Alternatively you can use MySSOServer as library class. In that case pass option `fail_exception` to the constructor. This will make the object throw a Jasny\\SSO\\Exception, rather than set the HTTP response and exit.

For more information, checkout the `server` example.

#### Broker

[](#broker)

When creating a Jasny\\SSO\\Broker instance, you need to pass the server url, broker id and broker secret. The broker id and secret needs to be registered at the server (so fetched when using `getBrokerInfo($brokerId)`).

**Be careful**: *The broker id SHOULD be alphanumeric. In any case it MUST NOT contain the "-" character.*

Next you need to call `attach()`. This will generate a token an redirect the client to the server to attach the token to the client's session. If the client is already attached, the function will simply return.

When the session is attached you can do actions as login/logout or get the user's info.

```
$broker = new Jasny\SSO\Broker($serverUrl, $brokerId, $brokerSecret);
$broker->attach();

$user = $broker->getUserInfo();
echo json_encode($user);
```

For more information, checkout the `broker` and `ajax-broker` example.

Examples
--------

[](#examples)

There is an example server and two example brokers. One with normal redirects and one using [JSONP](https://en.wikipedia.org/wiki/JSONP) / AJAX.

To proof it's working you should setup the server and two or more brokers, each on their own machine and their own (sub)domain. However you can also run both server and brokers on your own machine, simply to test it out.

On \*nix (Linux / Unix / OSX) run:

```
php -S localhost:9000 -t examples/server/
export SSO_SERVER=http://localhost:9000 SSO_BROKER_ID=Alice SSO_BROKER_SECRET=8iwzik1bwd; php -S localhost:9001 -t examples/broker/
export SSO_SERVER=http://localhost:9000 SSO_BROKER_ID=Greg SSO_BROKER_SECRET=7pypoox2pc; php -S localhost:9002 -t examples/broker/
export SSO_SERVER=http://localhost:9000 SSO_BROKER_ID=Julias SSO_BROKER_SECRET=ceda63kmhp; php -S localhost:9003 -t examples/ajax-broker/

```

Now open some tabs and visit ,  and . username/password jackie/jackie123 john/john123

*Note that after logging in, you need to refresh on the other brokers to see the effect.*

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 51.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Recently: every ~267 days

Total

18

Last Release

2302d ago

Major Versions

v0.4.2 → v1.x-dev2020-01-29

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v0.1.1PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5a13aaff462ca30ea692368d1a07f1c65f37a95d77655be3f3fe4bbe12464613?d=identicon)[adarmanto](/maintainers/adarmanto)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (51 commits)")[![TengenJulian](https://avatars.githubusercontent.com/u/3520504?v=4)](https://github.com/TengenJulian "TengenJulian (16 commits)")[![ludovic-berlemont-oxand](https://avatars.githubusercontent.com/u/157797370?v=4)](https://github.com/ludovic-berlemont-oxand "ludovic-berlemont-oxand (9 commits)")[![svenstm](https://avatars.githubusercontent.com/u/1632578?v=4)](https://github.com/svenstm "svenstm (6 commits)")[![adarmanto](https://avatars.githubusercontent.com/u/26041956?v=4)](https://github.com/adarmanto "adarmanto (6 commits)")[![poratuk](https://avatars.githubusercontent.com/u/12087528?v=4)](https://github.com/poratuk "poratuk (3 commits)")[![JeremyLWright](https://avatars.githubusercontent.com/u/2302957?v=4)](https://github.com/JeremyLWright "JeremyLWright (2 commits)")[![TJRoger](https://avatars.githubusercontent.com/u/4734434?v=4)](https://github.com/TJRoger "TJRoger (1 commits)")[![crzidea](https://avatars.githubusercontent.com/u/4723660?v=4)](https://github.com/crzidea "crzidea (1 commits)")[![kimjangwook](https://avatars.githubusercontent.com/u/14495700?v=4)](https://github.com/kimjangwook "kimjangwook (1 commits)")[![munvier](https://avatars.githubusercontent.com/u/2690700?v=4)](https://github.com/munvier "munvier (1 commits)")[![subdee](https://avatars.githubusercontent.com/u/1172323?v=4)](https://github.com/subdee "subdee (1 commits)")[![abemedia](https://avatars.githubusercontent.com/u/4355715?v=4)](https://github.com/abemedia "abemedia (1 commits)")

---

Tags

ssoauthSSO

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/yuca-sso/health.svg)

```
[![Health](https://phpackages.com/badges/yuca-sso/health.svg)](https://phpackages.com/packages/yuca-sso)
```

###  Alternatives

[jasny/sso

Simple Single Sign-On

1.5k255.9k6](/packages/jasny-sso)[codegreencreative/laravel-samlidp

Make your PHP Laravel application an Identification Provider using SAML 2.0. This package allows you to implement your own Identification Provider (idP) using the SAML 2.0 standard to be used with supporting SAML 2.0 Service Providers (SP).

263763.5k1](/packages/codegreencreative-laravel-samlidp)[maicol07/flarum-ext-sso

SSO for Flarum

468.3k](/packages/maicol07-flarum-ext-sso)[casdoor/casdoor-php-sdk

PHP client SDK for Casdoor

2219.3k](/packages/casdoor-casdoor-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
