faustoq / laravel-passport-claims

Add claims to Laravel Passport JWT Tokens

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

laravel-passport-claims

Latest Version on Packagist Total Downloads

This package allows you to add claims to Laravel Passport JWT Tokens. If you have questions or comments, please open an issue.

Installation

Via Composer

$ composer require corbosman/laravel-passport-claims

To collect all the claims, this package sends the access token through a pipeline of classes. Each class adds a claim to the token. For each claim that you want to add, you need to create a class like the example below. Because the AccessToken is sent through the pipeline, you have access to methods on the AccessToken class. This is useful if you want to derive information from the token. For instance, look up user data based on the token user identifier.

<?php

namespace App\Claims;

class CustomClaim
{
    public function handle($token, $next)
    {
        $token->addClaim('my-claim', 'my custom claim data');

        return $next($token);
    }
}

To tell this package which claims you want to add, you need to publish the config file and add a list of all your classes. To publish the config file, run the following command after installing this package.

php artisan vendor:publish --provider="CorBosman\Passport\ServiceProvider"

The config file will look like this.

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | JWT Claim Classes
    |--------------------------------------------------------------------------
    |
    | Here you can add an array of classes that will each be called to add
    | claims to the passport JWT token. See the readme for the interface that
    | these classes should adhere to.
    |
    */
    'claims' => [
        App\Claims\MyCustomClaim::class,
        App\Claims\MyOtherCustomClaim::class
    ]
];

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

Credits

License

Please see the license file for more information.

About

Add claims to Laravel Passport JWT Tokens

License:MIT License


Languages

Language:PHP 100.0%