Download the PHP package jeffersongoncalves/laravel-sso-client without Composer

On this page you can find all versions of the php package jeffersongoncalves/laravel-sso-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-sso-client

![Laravel SSO Client](art/jeffersongoncalves-laravel-sso-client.png)

Laravel SSO Client

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

SSO client for Laravel apps that authenticate against jeffersongoncalves/laravel-sso-server: Authorization Code + PKCE login, RS256/JWKS or signed userinfo token validation, local user sync and back-channel Single Logout.

Compatibility

Package PHP Laravel laravel-sso-server
1.x 8.2+ 12.x, 13.x 1.x (1.1+ for email_verified and client-initiated logout)

Installation

On the server app, register this client (prints the client_id and client_secret):

On the client app:

The migration adds a nullable, unique sso_id column to users: it stores the server's sub, the only stable identity of an SSO user.

The redirect URI sent to the server defaults to this package's callback route and must match the registered one exactly (override with SSO_REDIRECT_URI).

Usage

Protect routes with the sso.auth middleware. Guests are sent to the SSO Server and come back to the URL they asked for; sessions revoked by Single Logout are ended here too:

Routes registered by the package (prefix configurable via sso-client.route.prefix):

Method URI Name Purpose
GET /sso/redirect sso-client.redirect Starts the flow (state + PKCE S256)
GET /sso/callback sso-client.callback Checks state, exchanges the code, logs in
POST /sso/logout sso-client.logout Ends the local session, then the SSO session and the user's other apps (CSRF-protected)
POST /sso/slo-webhook sso-client.slo-webhook Back-channel Single Logout (no session, no CSRF, HMAC-authenticated)

The server paths (/sso/authorize, /sso/token, /sso/userinfo, /sso/logout, /.well-known/jwks.json) are configurable in sso-client.endpoints to follow the server's route prefix.

Logging out

Point the app's logout button at sso-client.logout:

The local session is destroyed first; then the browser goes to the server (laravel-sso-server 1.1+), which ends the SSO session, sends the Single Logout webhook to the user's other client apps and returns to sso-client.post_logout_redirect_uri (default: the home URL; it must share the origin of the redirect URI). Users who did not sign in through SSO are only logged out locally.

Custom user synchronization

The default synchronizer links local users to the server's sub (sso-client.user.sso_id_column) and keeps the columns in sso-client.user.attributes in sync (name and email with the server's default serializer). New users get a random, unusable password.

Situation on login Result
A user with this sub exists Updated and logged in (even if the email changed on the server)
No user with this sub or this email Created and linked
A local user with this email exists, not linked Rejected (AccountLinkingException, 401) unless link_existing_users_by_email is true and the email_verified claim is true
A local user with this email is linked to another sub Always rejected

Emails are mutable, so trusting an unverified one to take over an existing account would let anyone who registers that address on the server sign in as the local user. laravel-sso-server 1.1+ sends an email_verified claim, and email linking is refused unless it is exactly true; older servers do not send it, and then link_existing_users_by_email => true is your statement that the server verifies every email. Enable the flag only when needed (e.g. to adopt pre-SSO accounts). Setting sso_id_column => null matches users by email only (legacy mode); existing users are still refused when email_verified is false.

To keep users in memory only or map roles, implement the contract and set sso-client.synchronizer:

Events

Event When
UserSynchronizedEvent After the synchronizer returns, before login ($user, $ssoPayload)
SsoLoginFailedEvent Any callback failure ($exception); the browser only gets a generic 401
SsoRemoteLogoutReceivedEvent A new, valid Single Logout webhook ($sub: the server user id)

Failures are subclasses of SsoClientException: InvalidStateException, InvalidSignatureException, TokenExpiredException, SsoClientMismatchException (wrong iss/aud, or invalid_client), TokenReplayedException, SsoServerUnreachableException, AccountLinkingException.

How it works

  1. Authorize. /sso/redirect stores a random state (40 chars) and code_verifier (64 chars) in the session and redirects to {server}/sso/authorize with code_challenge = base64url(sha256(verifier)) and code_challenge_method=S256.
  2. Callback. The state is pulled from the session (single use) and compared with hash_equals. The code is exchanged right away (it lives 60 s and is burned on any attempt) with a form POST {server}/sso/token carrying client_id, client_secret, code, redirect_uri and code_verifier. Only network failures are retried (3 attempts, 100 ms apart); invalid_request/invalid_grant/invalid_client fail immediately.
  3. Verification.
    • jwks: the access_token is verified locally against {server}/.well-known/jwks.json (cached for jwks_cache_ttl, refetched once on an unknown kid, so key rotation just works). Only RS256 is accepted; iss, aud, exp, nbf (with leeway) are checked and each jti is accepted once.
    • userinfo: GET {server}/sso/userinfo with the Bearer token. The response must carry a valid X-SSO-Signature over the raw body and a fresh X-SSO-Timestamp. Costs a round-trip, but the server rejects users who already logged out.
  4. Login. The synchronizer resolves the local user by sub (see the table above), which is logged into the configured guard; the session is regenerated and remembers the server sub and the access token (the token_hint for logout).
  5. Client-initiated logout. POST /sso/logout destroys the local session and redirects to {server}/sso/logout?client_id=...&token_hint=...&post_logout_redirect_uri=.... The server revokes all of the user's SSO sessions and notifies every other client through the webhook below (not this one).
  6. Single Logout. When the user logs out on the server, it POSTs {"event":"logout","sub","aud","iat","jti"} to the webhook. The client checks X-SSO-Signature = HMAC-SHA256("{X-SSO-Timestamp}.{raw body}", client_secret) and a timestamp within signature_tolerance (300 s), then event and aud, and answers 204. A replayed jti is acknowledged but ignored, so the server stops retrying. Every local session of that sub started before the webhook is ended by sso.auth on its next request.

Production notes

Testing

The suite includes interop tests that run the real laravel-sso-server (dev dependency) against this client: login in both verification modes and Single Logout.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security

If you discover any security related issues, please email the author instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-sso-client with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
spatie/laravel-package-tools Version ^1.16
firebase/php-jwt Version ^7.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jeffersongoncalves/laravel-sso-client contains the following files

Loading the files please wait ...