A custom user provider to authenticate users to REST API within Laravel framework.
elzdave/benevolent is a Laravel package for a custom user provider to authenticate users to rest api within laravel framework..
It currently has 0 GitHub stars and 6 downloads on Packagist (latest version v1.0.0).
Install it with composer require elzdave/benevolent.
Discover more Laravel packages by elzdave
or browse all Laravel packages to compare alternatives.
Last updated
Imagine you built a Laravel-powered website, which needs to communicates to your external API server using REST API. Some of the HTTP requests needs to be authenticated by including access token to the Authorization header. To get the access token, you first authenticate the user to the API server, and then the server return the access token and user data in exchange. You store the access token to use it on every authenticated HTTP requests. All is well until you realize, that default Laravel authentication middleware cannot authenticate user to another server leveraging REST API, and you need to write new authentication logics to cover those requirements...
That's why this package exist. Just install this package, set the config, and you all done!
Require this package in the project.
$ composer require elzdave/benevolent
Publish the config after installation.
$ php artisan vendor:publish --tag=benevolent-config
config/auth.php, change the provider entry on guards.web to benevolent.env and .env.example, change <your-external-API-base-URI> to your authentication server's base URI, eg: https://server.api/v1EXT_API_BASE_URI=<your-external-API-base-URI>
config/benevolent.phpIf you want to make authenticated HTTP requests using the user's access token, use the Elzdave\Benevolent\Http\Http facade with useAuth() method
<?php
use Elzdave\Benevolent\Http\Http;
$data = [
'data' => 'some-data-to-store'
];
$apiRelativeUrl = 'path/relative/to/base-uri';
$apiResponse = Http::useAuth()->post($apiRelativeUrl, $data);
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email the author instead of using the issue tracker.
MIT. Please see the license file for more information.