Giter VIP home page Giter VIP logo

laravel-simple-jwt's Introduction

Laravel Simple JWT Authentication

CI Coverage Downloads Version License

composer require bayareawebpro/laravel-simple-jwt

Create Encryption Secret

artisan jwt:secret

Add Secret to Environment File

JWT_SECRET=XXX

Configure Auth.php

'guards' => [
    ...
    'api' => [
        'driver' => 'simple-jwt', 
        'provider' => 'users',
        'hash' => false,
    ],
],

Register in Auth Service Provider.

JsonWebToken::register(User::class, 'token');

Create New Token, Expiration, and Claims

$token = JsonWebToken::createForUser(User::first(), now()->addHours(3), [
  'my_key' => true
]);

Authenticate

Query String

http://laravel.test/api/user?token=xxx

Or Header

Authorization: Bearer XXX

Get Claims From Token

$request->jwt()->get('my_key');
$request->jwt('my_key');

Extend Token Lifetime & Claims

$newToken = JsonWebToken::extendToken(request()->jwt(), now()->addHours(3), ['key' => true]);

Blacklist Handler

$bannedUUID = request()->jwt('jti');
JsonWebToken::rejectionHandler(fn($parsed)=>in_array($parsed->get('jti'),[
    $bannedUUID
]));

Testing

composer test
composer lint

laravel-simple-jwt's People

Contributors

bayareawebpro avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

tzkmx

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.