PHPackages                             mikp/wn-sanctum-tokens-plugin - 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. mikp/wn-sanctum-tokens-plugin

ActiveWinter-plugin[Authentication &amp; Authorization](/categories/authentication)

mikp/wn-sanctum-tokens-plugin
=============================

Laravel Sanctum plugin for Winter CMS

v0.1.0(4y ago)5284BSD-3PHP

Since Jan 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mik-p/wn-sanctum-tokens-plugin)[ Packagist](https://packagist.org/packages/mikp/wn-sanctum-tokens-plugin)[ Docs](https://github.com/mik-p/wn-sanctum-tokens-plugin)[ RSS](/packages/mikp-wn-sanctum-tokens-plugin/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

wn-sanctum-tokens-plugin
========================

[](#wn-sanctum-tokens-plugin)

[![Buy me a tree](https://camo.githubusercontent.com/c1facc69655e7280a2c26e56bbe947bc0a91104505dc1c334fbd1de0f2152a6b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532306d6525323061253230747265652d2546302539462538432542332d677265656e)](https://ecologi.com/mik-p-online?gift-trees)[![Plant a Tree for Production](https://camo.githubusercontent.com/5922e16162f21a5439d7999be04a277275210f52635142548c30986aeb46cdf0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f636f6c6f723d627269676874677265656e266c6162656c3d506c616e742532306125323054726565253230666f7225323050726f64756374696f6e2671756572793d2532342e746f74616c2675726c3d68747470732533412532462532467075626c69632e6f66667365742e6561727468253246757365727325324674726565776172652532467472656573)](https://plant.treeware.earth/mik-p/wn-sanctum-tokens-plugin)

Add Laravel Sanctum API Tokens to Winter.Users to allow API Auth via Sanctum tokens for front end users. It is useful if you need API Bearer Token Auth and don't want to go with OAuth2.

### depends on

[](#depends-on)

This plugin depends on [Laravel Sanctum](https://github.com/laravel/sanctum) for tokens

This plugin depends on the [Winter.User plugin](https://github.com/wintercms/wn-user-plugin) for users

#### .htaccess headers

[](#htaccess-headers)

The default wintercms settings do not allow the needed token header. If you are using Apache there is a console command and button in the backend settings to add the necessary modifications to the .htaccess file

```
# adds the following to the root .htaccess file

# ##
# ## Authorization header
# ##
# RewriteCond %{HTTP:Authorization} ^(.*)
# RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

php artisan sanctum:authorization --add
```

usage
-----

[](#usage)

There are 3 endpoints that can be used to interact with tokens

- {POST} `api/v1/sanctum/token/create`
- {POST} `api/v1/sanctum/token/refresh`
- {POST} `api/v1/sanctum/token/revoke/{tokenId}`

The **'create'** endpoint does not act as a log in, it is guarded with the \\Winter\\User\\Classes\\AuthMiddleware which means the user must already be logged in.

The other endpoints are guarded via token so you need to `create` a token and provide it as Authorization before you can `revoke` or `refresh` any.

### middleware

[](#middleware)

There are three middleware classes:

1. HasBearerToken =&gt; allow if there is a valid token present
2. UserFromBearerToken =&gt; log the user in using a valid token
3. SoftUserFromBearerToken =&gt; try to log the user in with a valid token or give up and pass the request on to next middleware

Add the provided middleware to routes for example:

```
// in your plugin's routes.php file

Route::group([
    'prefix' => 'api',
    'middleware' => [
        'api',
        'mikp\sanctum\Http\Middleware\UserFromBearerToken'
    ]
], function () {

    // do a thing
    Route::post('/thing', 'Author\Plugin\Http\Controllers\API@thing');
});
```

### components

[](#components)

There is an api-token creation component that can be used to allow users to create and revoke their own tokens.

```
'mikp\sanctum\Components\CreateToken' => 'createtoken'
```

Licence
-------

[](#licence)

This package is [Treeware](https://treeware.earth). If you use it in production, then we ask that you [**buy the world a tree**](https://plant.treeware.earth/mik-p/wn-sanctum-tokens-plugin) to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

###  Health Score

23

—

LowBetter than 25% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1679d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd7109b68ff361e25ab12fea248168723e4e636028f950903e83485e763b9938?d=identicon)[mikp](/maintainers/mikp)

---

Top Contributors

[![mik-p](https://avatars.githubusercontent.com/u/45908907?v=4)](https://github.com/mik-p "mik-p (7 commits)")

### Embed Badge

![Health badge](/badges/mikp-wn-sanctum-tokens-plugin/health.svg)

```
[![Health](https://phpackages.com/badges/mikp-wn-sanctum-tokens-plugin/health.svg)](https://phpackages.com/packages/mikp-wn-sanctum-tokens-plugin)
```

###  Alternatives

[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.6k10](/packages/helsingborg-stad-municipio)[unopim/unopim

UnoPim Laravel PIM

10.8k2.5k](/packages/unopim-unopim)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6796.8k7](/packages/hasinhayder-tyro)[rainlab/user-plugin

User plugin for October CMS

11855.3k17](/packages/rainlab-user-plugin)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)[civicrm/civicrm-drupal-8

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

20256.6k4](/packages/civicrm-civicrm-drupal-8)

PHPackages © 2026

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