PHPackages                             elzdave/benevolent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. elzdave/benevolent

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

elzdave/benevolent
==================

A custom user provider to authenticate users to REST API within Laravel framework.

v1.0.0(3y ago)06MITPHP

Since Jun 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/elzdave/benevolent)[ Packagist](https://packagist.org/packages/elzdave/benevolent)[ Docs](https://github.com/elzdave/benevolent)[ RSS](/packages/elzdave-benevolent/feed)WikiDiscussions main Synced 5d ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

Benevolent
==========

[](#benevolent)

[![Latest Version on Packagist](https://camo.githubusercontent.com/60dd83a8a7210f790d1e7d7d53d3df7b33106804ac04bc64e0d3c690481f55be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656c7a646176652f62656e65766f6c656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elzdave/benevolent)[![Total Downloads](https://camo.githubusercontent.com/756ff824f272493c4ce2451ea87cab15ad26da9e936806f5787c8ca355b12e6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656c7a646176652f62656e65766f6c656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/elzdave/benevolent)[![Build Status](https://camo.githubusercontent.com/bc4911fa78312bd5ea021afbbab68697229add15f95fa158bed43173cb77e7f3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f656c7a646176652f62656e65766f6c656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/elzdave/benevolent)[![StyleCI](https://camo.githubusercontent.com/cb13a877afd1dbe223c631789c3f922d3ace958fdb334a9cce9b26afefbc2ebd/68747470733a2f2f7374796c6563692e696f2f7265706f732f31323334353637382f736869656c64)](https://styleci.io/repos/12345678)

Use Case
--------

[](#use-case)

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!

Installation
------------

[](#installation)

### Laravel

[](#laravel)

Require this package in the project.

```
$ composer require elzdave/benevolent
```

Publish the config after installation.

```
$ php artisan vendor:publish --tag=benevolent-config
```

Usage
-----

[](#usage)

### User Authentication

[](#user-authentication)

1. At the `config/auth.php`, change the `provider` entry on `guards.web` to `benevolent`
2. Add the new entry on `.env` and `.env.example`, change `` to your authentication server's base URI, eg:

```
EXT_API_BASE_URI=
```

3. Optional: adjust some settings to suit your API server design at `config/benevolent.php`

### Making Authenticated HTTP Request using Authorization header

[](#making-authenticated-http-request-using-authorization-header)

If you want to make authenticated HTTP requests using the user's access token, use the `Elzdave\Benevolent\Http\Http` facade with `useAuth()` method

```
