承接 laranex/laravel-refresh-token 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laranex/laravel-refresh-token

最新稳定版本:v1.0.0

Composer 安装命令:

composer require laranex/laravel-refresh-token

包简介

A package to help you implement refresh token mechanism in your laravel application

README 文档

README

Latest Version on Packagist Total Downloads run-tests

A package to help you implement refresh token mechanism in your laravel application

Installation

You can install the package via composer:

  composer require laranex/laravel-refresh-token

Generate encryption keys

  php artisan refresh-token:keys

Run The migration file

  php artisan migrate

You can publish the config file with:

  php artisan vendor:publish --tag="refresh-token-config"

This is the contents of the published config file:

    return [
    
        /*
        |--------------------------------------------------------------------------
        | Encryption Keys
        |--------------------------------------------------------------------------
        |
        | Refresh Token uses encryption keys while generating secure access tokens for
        | your application. By default, the keys are stored as local files but
        | can be set via environment variables when that is more convenient.
        |
        */
        'private_key' => env('REFRESH_TOKEN_PRIVATE_KEY'),
    
        'public_key' => env('REFRESH_TOKEN_PUBLIC_KEY'),
    
        /*
        |--------------------------------------------------------------------------
        | Refresh Token Model
        |--------------------------------------------------------------------------
        |
        | Refresh Token Model to manage refresh tokens
        |
        */
        'model' => RefreshToken::class,
    
        /*
        |--------------------------------------------------------------------------
        | Refresh Token Table
        |--------------------------------------------------------------------------
        |
        | Refresh Token Model to manage refresh tokens
        |
        */
        'table' => 'laravel_refresh_tokens',
    ];

Overriding the default values (Optional)

The following static methods are available under the Laranex\RefreshToken\RefreshToken class to override the default values. Invoking them with the value you want in the service provider will override the default values.

  • useRefreshTokenModel(string $refreshTokenModel): void
  • loadKeysFrom(string $path): void
  • refreshTokensExpireIn(DateTimeInterface $date = null): DateInterval|static

Usage

  • Use the trait in your refresh tokenable model
    class User extends Authenticatable{
        use HasRefreshTokens;
    
    }
  • Create a refresh token

    $user = Auth::user()->createRefreshToken();
  • Verify a refresh token

    • a token instance will be return if the token is valid, or else null will be return
    $verifiedToken = Laranex\RefreshToken\RefreshToken::tokenable($request->get('refresh_token'));
    if ($verifiedToken) {
    // Implement your access token logic here
    
    } else {
    // handle invalid refresh token
    }
  • Working with verified refresh token

        $verifiedToken = Laranex\RefreshToken\RefreshToken::tokenable($request->get('refresh_token'));
    • You can access the token instance by calling the instance property, The instance property will return the model instance that you use the RefreshToken trait in

          $tokenInstance = $verifiedToken->instance;
    • Revoking the refresh token (The token will no longer be valid)

          $verifiedToken->revoke();
    • Revoking all refresh tokens which are related to current refresh token instance

          $verifiedToken->revokeAll();

Prune Command

  • You can use the prune command to delete all expired refresh tokens
        php artisan refresh-token:prune
  • Or you can put this into a scheduler to run it periodically
        $schedule->command('refresh-token:prune')->daily();

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 782
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固