asseco-voice/laravel-jwt-authentication

Package to decode and verify JWT tokens
7,684 1
Install
composer require asseco-voice/laravel-jwt-authentication
Latest Version:v3.0.1
PHP:^8.1
License:MIT
Last Updated:Dec 3, 2024
Links: GitHub  ·  Packagist
Maintainer: Norgul

Laravel JWT Authentication

This package enables backend authentication via JWT-token

Installation

Install the package through composer. It is automatically registered as a Laravel service provider, so no additional actions are required to register the package.

composer require asseco-voice/laravel-jwt-authentication

In order to gain access to additional configuration run

php artisan vendor:publish

This will publish the asseco-authentication.php configuration file into your config directory

Quick usage

A minimal requirement to make the package work is to set the JWT_PUBLIC_KEY in your .env file. This is the location of the public key with which the package will verify the signature of the token.

The package works out-of-the-box. Once installed the application will have a new guard registered.

'jwt-api' => [
   'driver' => 'token',
   'provider' => 'token_provider',
],

Activating it on your desired route follows the standard laravel implementation.

Route::apiResource('YourResource', 'YourController')->middleware('auth:jwt-api');

This will force the framework to use the following configuration to resolve the user from a JWT-token and injecting it as the authenticated user.

'token_provider' => [
    'driver' => 'jwt_provider'
]

The public.pem key will be fetched on the first incoming request from the configured AUTH_URL

Fetch key command

Package comes with a convenience command. The only requirement is the env value AUTH_URL.

php artisan asseco:fetch-key

The method is made to hit the configured endpoint and extract the public key from the response. By default, the command will look for the key public_key in the response, however this can be configured through a config file.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
v3.0.1 ^8.1 ^10.0 MIT
v3.0.0 ^8.1 ^10.0 MIT
v2.1.0 ^8.0 ^9.0 MIT
v2.0.1 ^8.0 ^9.0 MIT
v2.0.0 ^8.0 ^9.0 MIT