Download the PHP package danilopolani/laravel-fusionauth-jwt without Composer
On this page you can find all versions of the php package danilopolani/laravel-fusionauth-jwt. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danilopolani/laravel-fusionauth-jwt
More information about danilopolani/laravel-fusionauth-jwt
Files in danilopolani/laravel-fusionauth-jwt
Package laravel-fusionauth-jwt
Short Description Laravel Auth guard for FusionAuth JWT
License MIT
Homepage https://github.com/danilopolani/laravel-fusionauth-jwt
Informations about the package laravel-fusionauth-jwt
Laravel FusionAuth JWT
Implement an Auth guard for FusionAuth JWTs in Laravel.
It ships with also a middleware to check against the user role.
Installation
You can install the package via composer:
Then publish its config file:
Configuration
There are a few notable configuration options for the package.
Key | Type | Description |
---|---|---|
domain |
String | Your FusionAuth domain, e.g. auth.myapp.com or sandbox.fusionauth.io . |
client_id |
String | The Client ID of the current application. |
client_secret |
String | The Client Secret of the current application. |
issuers |
Array | A list of authorized issuers for the incoming JWT. |
audience |
String | Null | The ID/Name of the authorized audience. If null, the Client ID will be used. |
supported_algs |
Array | The supported algorithms of the JWT. Supported: RS256 and HS256 . |
default_role |
String | Null | The default role to be checked if you're using the CheckRole middleware. |
Usage
To start protecting your APIs you need to add the Guard and the Auth Provider to your config/auth.php
configuration file:
Then you can use the auth:fusionauth
guard to protect your endpoints; you can apply it to a group or a single route:
Now requests for those endpoints will check if the given JWT (given as Bearer token) is valid.
To retrieve the current logged in user - or to check if it's logged in - you can use the usual Auth
facade methods, specifying the fusionauth
guard:
Role middleware
The package ships with a handy middleware to check for user role (stored in the roles
key).
You can apply it on a middleware group inside the Kernel.php
or to specific routes:
By default the middleware will check that the current user has the default_role
specified in the configuration file, but you can use as well a specific role, different from the default:
For more complex cases we suggest you to take a look on how the CheckRole
middleware is written (using the RoleManager
class) and write your own.
Usage in tests
When you need to test your endpoints in Laravel, you can take advantage of the actingAs
method to set the current logged in user.
You can pass any property you want to the FusionAuthJwtUser
class, like email
, user
etc. Take a look at this example where we specify the user roles:
If you need to set the authenticated user outside HTTP testing (therefore you can't use actingAs()
), you can use the setUser()
method of the Auth
facade:
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Danilo Polani
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
All versions of laravel-fusionauth-jwt with dependencies
firebase/php-jwt Version ^6.4
illuminate/auth Version ^10.0|^11.0
illuminate/http Version ^10.0|^11.0
illuminate/contracts Version ^10.0|^11.0
illuminate/routing Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0