PHPackages                             jundayw/laravel-tokens - 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. jundayw/laravel-tokens

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

jundayw/laravel-tokens
======================

laravel tokens

v2.0.0(5y ago)038MITPHPPHP &gt;=7.2.0

Since Jul 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/jundayw/laravel-tokens)[ Packagist](https://packagist.org/packages/jundayw/laravel-tokens)[ RSS](/packages/jundayw-laravel-tokens/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

安装方法
====

[](#安装方法)

命令行下, 执行 composer 命令安装:

```
composer require jundayw/laravel-tokens

```

使用方法
====

[](#使用方法)

authentication package that is simple and enjoyable to use.

配置方法
====

[](#配置方法)

将配置文件 auth.php 中 guards 的 driver 字段修改为 tokens

```
'guards' => [
    'web' => [
        'driver' => 'tokens',
        'provider' => 'users',
    ],
],
```

用户信息获取、登录及退出操作

```
use Jundayw\LaravelTokens\HasTokens;
use Jundayw\LaravelTokens\HasTokensContract;

class User extends Authenticatable implements HasTokensContract
{
    use HasTokens;

    public function login(Request $request){
        $guard = config("auth.defaults.guard");// web
        $provider = config("auth.guards.{$guard}.provider");// users
        $model = config("auth.providers.{$provider}.model");// App\User::class
        //获取默认用户 guard 配置，可根据业务情况获取 $guard 及 $model 参数
        $user = $request->user($guard);
        //登录逻辑
        Auth::guard($guard)->claims([
            'iss' => $model,
            'sub' => 'android',// web,ios,android 也可传入 user-agent 确定用户唯一性
            'aud' => 'weixin',// pc,weixin,alipay 也可传入 user-agent 确定用户唯一性
        ])->login(User::find(1));
        //退出登录
        Auth::guard($guard)->logout();
    }
}
```

发布配置文件
------

[](#发布配置文件)

```
php artisan vendor:publish --tag=tokens-config

```

发布迁移文件
------

[](#发布迁移文件)

```
php artisan vendor:publish --tag=tokens-migrations

```

发布迁移文件仅在同一用户不允许多端同时登陆时需要，并且需要：

1、通过 Auth::extend 扩展 TokensGuard 类；

2、重写 TokensGuard 类的 login 方法，将用户信息写入 tokens 表；

3、重写 TokensGuard 类的 getTokensForRequest 方法判定当前用户(tokens 表的 tokens\_revoked 字段)是否已被挤下线。

###  Health Score

24

—

LowBetter than 30% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Every ~68 days

Total

2

Last Release

2151d ago

Major Versions

v1.0.0 → v2.0.02020-09-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16873970?v=4)[Xander Moore](/maintainers/jundayw)[@jundayw](https://github.com/jundayw)

---

Top Contributors

[![jundayw](https://avatars.githubusercontent.com/u/16873970?v=4)](https://github.com/jundayw "jundayw (5 commits)")

### Embed Badge

![Health badge](/badges/jundayw-laravel-tokens/health.svg)

```
[![Health](https://phpackages.com/badges/jundayw-laravel-tokens/health.svg)](https://phpackages.com/packages/jundayw-laravel-tokens)
```

###  Alternatives

[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

84511.6M67](/packages/php-open-source-saver-jwt-auth)[scheb/2fa

Two-factor authentication for Symfony applications (please use scheb/2fa-bundle to install)

589701.7k2](/packages/scheb-2fa)[scheb/2fa-trusted-device

Extends scheb/2fa-bundle with trusted devices support

366.0M40](/packages/scheb-2fa-trusted-device)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.8M674](/packages/shopware-core)[jeremy379/laravel-openid-connect

OpenID Connect support to the PHP League's OAuth2 Server. Compatible with Laravel Passport.

62473.7k10](/packages/jeremy379-laravel-openid-connect)[drenso/symfony-oidc-bundle

OpenID connect bundle for Symfony

97795.4k4](/packages/drenso-symfony-oidc-bundle)

PHPackages © 2026

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