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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

2053d ago

Major Versions

v1.0.0 → v2.0.02020-09-28

### Community

Maintainers

![](https://www.gravatar.com/avatar/2da9b458375a1b7972b7c4d26a5bf8f3e48db305e8805da36f253956f33c5568?d=identicon)[jundayw](/maintainers/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

[tymon/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

11.5k49.1M350](/packages/tymon-jwt-auth)[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.6k136.0M248](/packages/league-oauth2-server)[php-open-source-saver/jwt-auth

JSON Web Token Authentication for Laravel and Lumen

8359.8M53](/packages/php-open-source-saver-jwt-auth)[kreait/firebase-tokens

A library to work with Firebase tokens

24040.8M14](/packages/kreait-firebase-tokens)[scheb/2fa

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

578630.7k1](/packages/scheb-2fa)[steverhoades/oauth2-openid-connect-server

An OpenID Connect Server that sites on The PHP League's OAuth2 Server

2097.8M12](/packages/steverhoades-oauth2-openid-connect-server)

PHPackages © 2026

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