Download the PHP package simplesquid/saloonphp-oauth without Composer

On this page you can find all versions of the php package simplesquid/saloonphp-oauth. 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 saloonphp-oauth

Saloon OAuth Auto-Refresh

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

Automatic, concurrent-safe OAuth token management for Saloon v4 connectors in Laravel. Handles refresh for the Authorization Code grant, caching for the Client Credentials grant, and uses a distributed lock so two processes don't refresh the same token at the same time.

Requirements

Installation

Publish and run the migration:

Optionally publish the config:

Usage

Authorization Code Flow

Add the HasAutoRefresh trait to a connector using Saloon's AuthorizationCodeGrant. The only method you need to implement is resolveTokenKey():

When you send a request, defaultAuth() loads the token from the store, checks expiry, and refreshes it if needed — all within a distributed lock.

Client Credentials Flow

Add the HasClientCredentialsCache trait. No extra methods are required — the token key defaults to the connector's class name, so one token is cached per connector class:

When no token exists or the current one is expired, a new token is acquired automatically.

Storing the Initial Token

This step is only needed for the Authorization Code flow — client credentials tokens are acquired automatically on first use.

After the OAuth callback, persist the token so HasAutoRefresh can find it on subsequent requests:

Revoking a Token

See Revoke vs Forget for the difference between soft-revocation and hard-deletion.

Configuration

Customization

Each connector resolves four protected methods. Override any of them to change behaviour for that connector:

Method Default Purpose
resolveTokenKey() abstract on HasAutoRefresh; static::class on HasClientCredentialsCache Unique key for this connector's token
resolveTokenStore() app(TokenStore::class) Token persistence backend
resolveTokenLocker() app(TokenLocker::class) Distributed lock implementation
resolveExpiryBuffer() config('saloon-oauth.expiry_buffer') Seconds before expiry to trigger a proactive refresh

For application-wide changes, rebind the contracts in a service provider instead:

Token Store

The default EloquentTokenStore persists tokens to the oauth_tokens table via the OAuthToken model. Any implementation of the TokenStore contract can replace it.

Custom model. To add relationships, scopes, or extra columns, extend OAuthToken and point the config at your class:

If you add columns, follow up with your own migration — don't edit the published one.

Custom table. Change config('saloon-oauth.table'). The default model reads this value from getTable().

Custom backend. Implement the TokenStore contract. Required invariants:

Token Locker

CacheTokenLocker delegates to a Laravel cache store's LockProvider. The two timeouts control different things:

Override per-connector, or rebind globally:

For single-process contexts where locking is unnecessary (tests, one-off artisan commands), use NullLocker — it just calls the callback.

Expiry Buffer

Tokens are treated as expired expiry_buffer seconds before their actual expiry. The default of 300 seconds gives the refresh enough headroom to complete before the in-flight token dies. Shorter values mean tokens are used closer to their real lifetime; longer values refresh more eagerly.

A token with a null expiresAt is treated as non-expiring — it won't be refreshed until revoked or forgotten.

Storage Details

Schema

Column Type Notes
id bigint Primary key
key string, unique Your application-defined key (e.g. "user:42:exact-online")
access_token text Encrypted at rest via Laravel's encrypted cast (APP_KEY required)
refresh_token text, nullable Encrypted at rest
expires_at timestamp, nullable When the access token expires; null means never
revoked_at timestamp, nullable, indexed Set by revoke(); non-null means the token is dead
created_at / updated_at timestamps Standard Eloquent timestamps

Key Conventions

Keys are free-form strings you choose per authentication context. Keep them stable — don't embed things like request IDs. Common patterns:

Keys must fit in varchar(255).

Revoke vs Forget

Failure Semantics

The traits surface failures through custom exceptions and degrade gracefully where they can:

Exception When
TokenRevokedException A revoked token is loaded — or a concurrent refresh tries to persist over a key that was revoked mid-refresh
TokenAcquisitionFailedException Refresh or acquisition failed; wraps the underlying Saloon exception
LockTimeoutException Couldn't acquire the lock within lock.wait
InvalidCacheStoreException Configured cache store doesn't implement LockProvider

Transient persist failures are non-fatal. If the refresh HTTP call succeeds but $store->put() fails (DB outage, etc.), the exception is sent through Laravel's report() helper and the fresh token is still returned to the caller. The current request succeeds; the next request will retry the refresh.

Concurrent revokes are respected. If a revoke lands while a refresh is in flight, put() refuses to overwrite the revoked row and throws TokenRevokedException. The current request fails — matching the intent of the revocation — and the token stays dead.

Testing

The package ships two test doubles:

Either inject them into your connector via the resolver overrides, or rebind the contracts in your test's service container.

Run the package's own tests with:

Changelog

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

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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


All versions of saloonphp-oauth with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/support Version ^12.0 || ^13.0
saloonphp/saloon Version ^4.0
spatie/laravel-package-tools Version ^1.16
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 simplesquid/saloonphp-oauth contains the following files

Loading the files please wait ...