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)5254BSD-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 1mo 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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

1581d 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

[hasinhayder/tyro

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

6712.1k2](/packages/hasinhayder-tyro)[rainlab/user-plugin

User plugin for October CMS

11954.3k13](/packages/rainlab-user-plugin)[stuttter/wp-user-signups

The best way to manage user &amp; site sign-ups in WordPress

46208.9k5](/packages/stuttter-wp-user-signups)[winter/wn-user-plugin

User plugin for Winter CMS

1233.5k13](/packages/winter-wn-user-plugin)[rainlab/userplus-plugin

User plus plugin for October CMS

168.8k2](/packages/rainlab-userplus-plugin)

PHPackages © 2026

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