Download the PHP package d076/sanctum-refresh-tokens without Composer

On this page you can find all versions of the php package d076/sanctum-refresh-tokens. 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 sanctum-refresh-tokens

Laravel Sanctum Refresh Tokens

Tests Latest Version

Refresh tokens on top of Laravel Sanctum. Sanctum issues long-lived personal access tokens; this package adds a short-lived access token paired with a longer-lived, single-use refresh token, so a client can silently obtain a fresh pair without re-authenticating — the standard pattern for SPAs and mobile apps.

Features

Requirements

Version
PHP ^8.3
Laravel 12, 13
Sanctum ^4.0

Tested against PHP 8.3 / 8.4 / 8.5 and Laravel 12 / 13 on SQLite, PostgreSQL and MySQL.

Installation

Publish and run the migration (creates the personal_refresh_tokens table):

This package builds on Sanctum's personal_access_tokens table, so make sure Sanctum itself is installed and migrated (php artisan install:api on a fresh app).

Upgrading from 3.x

4.0 adds an abilities column to personal_refresh_tokens (so a token's scope is preserved across refreshes). Re-publish and migrate to pick it up:

Refresh tokens issued before the upgrade have no stored scope and fall back to ['*'] on their next refresh.

Setup

Extend your authenticatable model from AuthenticatableUser:

AuthenticatableUser already pulls in Sanctum's HasApiTokens plus this package's refresh-token behaviour. If you can't change your base class, use the trait directly and implement the contract instead:

Configuration

Token lifetimes are read from Sanctum's config (config/sanctum.php). Add the keys this package uses alongside Sanctum's own:

If a key is absent the built-in defaults above are used, so the package works out of the box. The optional sanctum.token_prefix is honoured for refresh tokens too (useful for secret-scanning).

Usage

The package ships no routes or controllers — you stay in control of your API surface. Inject the services where you need them.

Issuing tokens

createTokens() accepts optional overrides:

It returns a TokensDTO:

Logging in with credentials

remember selects between the two refresh-token TTLs (refresh_token_expiration vs refresh_token_expiration_no_remember).

Already have the user (e.g. social login)? Skip credentials:

Refreshing

The old refresh token and its bound access token are deleted before the new pair is issued, so a stolen-and-replayed token is rejected on the second use.

Logout

Behind the auth:sanctum guard, the authenticated request carries the current access token, so logout can revoke exactly that pair:

Password reset

Hashes the new password, saves it, and revokes all of the user's access and refresh tokens:

Revoking tokens directly

Pruning expired tokens

A console command removes refresh tokens that expired more than --hours ago (default 24):

Schedule it next to Sanctum's own pruning:

Customisation

Custom email / password columns

If your model doesn't use email / password, expose the column names and the package will pick them up:

Swapping the service implementations

Both services are bound behind interfaces, so you can rebind your own in a service provider:

How it works

Testing

A Docker setup is included to run the suite (including the PostgreSQL/MySQL matrix):

Changelog & License

See MIT license.


All versions of sanctum-refresh-tokens with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
ext-json Version *
illuminate/auth Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/notifications Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
laravel/framework Version ^12.0|^13.0
laravel/sanctum Version ^4.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 d076/sanctum-refresh-tokens contains the following files

Loading the files please wait ...