Coder Social home page Coder Social logo

sanctum-refresh-token's Introduction

Sanctum Refresh Token

Add refresh token feature to laravel sanctum official package.

Install

$ composer require mohamedgaber-intake40/sanctum-refresh-token

The Package is auto discovered , but you can register Service Provider in config/app.php

 'providers' => [
    \MohamedGaber\SanctumRefreshToken\SanctumRefreshTokenServiceProvider::class
];
  • if you want to customize the migrations
$ php artisan vendor:publish --tag=sanctum-refresh-token-migrations
  • if you want to customize the config
$ php artisan vendor:publish --tag=sanctum-refresh-token-config
  • to publish both migrations and config
$ php artisan vendor:publish --provider="MohamedGaber\SanctumRefreshToken\SanctumRefreshTokenServiceProvider"

Usage

  • in tokenable model use this trait
use MohamedGaber\SanctumRefreshToken\Traits\HasApiTokens;

this will add createAuthToken , createRefreshToken methods to this model

for example: to create auth token for user

$user->createAuthToken('web');

//you can add expired minutes as a parameter
$user->createAuthToken('web',20);

//you can add abilities as a parameter like the official package
$user->createAuthToken('web',20,['test:update']);

then you need to create refresh token

$user->createRefreshToken('web');

//you can add expired minutes as a parameter
$user->createRefreshToken('web',20);

this token will be valid only for refresh route in sanctum-refresh-token.php config file

then you need to use auth:sanctum middleware for both authenticated routes and refresh routes


Notes

  • if you do not add expired minutes when creating auth token or refresh token , it will consider expired minutes from sanctum-refresh-token.php config file
  • make sure to set expiration to null in sanctum official package config file

sanctum-refresh-token's People

Contributors

mohamedgaber-intake40 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.