PHPackages                             keukenmagazijn/passport-authenticator - 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. keukenmagazijn/passport-authenticator

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

keukenmagazijn/passport-authenticator
=====================================

A superclass package that you can extend upon that will handle the authentication and refreshing of your access (bearer) tokens

1.1.5(4y ago)13.0k1MITPHPPHP &gt;=7.4

Since Jan 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/het-keukenmagazijn/passport-authenticator)[ Packagist](https://packagist.org/packages/keukenmagazijn/passport-authenticator)[ RSS](/packages/keukenmagazijn-passport-authenticator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (16)Used By (0)

Laravel Passport Authenticator
==============================

[](#laravel-passport-authenticator)

Introduction
------------

[](#introduction)

This package is a self-refreshing [Laravel Passport](https://laravel.com/docs/5.8/passport) authenticator. There are superclasses available with which you can make quick custom connectors for all your (micro)services and you will never have to worry about having to maintain, refresh or create your bearer tokens yourself.

**IMPORTANT!** This is for usage with password clients only: .

How to install
--------------

[](#how-to-install)

- You can install the package by requiring the `keukenmagazijn/passport-authenticator` package, or run `composer require keukenmagazijn/passport-authenticator` in your project root directory.
- When your package is included, you should run `php artisan migrate` to create the `external_oauth2_credentials` table, which the package requires to maintain your tokens.

How to use the package.
-----------------------

[](#how-to-use-the-package)

### The setup

[](#the-setup)

#### The configuration

[](#the-configuration)

The first recommended step is to create a config file for your passport, you don't *have* to but it's the clean thing to do. So let's say we have this config file available: `config/external_application.php`

```
return [
    'passport' => [
        'endpoints' => [
            'base_uri' => env('APP_BASE_URI', null), // https://external.app
            'authorize' => '/oauth/authorize', // Authorize our client and user route to retrieve a code.
            'token' => '/oauth/token' // Route we give our code to and get our tokens from.
        ],
        'user' => [
            'email' => env('APP_USER_EMAIL', null), // username of external app.
            'password' => env('APP_USER_PASSWORD', null), // password of external app.
        ],
        'secret' => env('APP_SECRET', null), // API client secret used to connect.
        'client_id' => env('APP_CLIENT_ID', null), // API client id used to connect .
        'redirect_uri' => env('APP_REDIRECT_URI', null), // API redirect uri.
    ]
];
```

#### Extending the Library superclasses

[](#extending-the-library-superclasses)

This library offers two superclasses, these need to be extended and available in order for the library to do its work properly.

##### The Authenticator

[](#the-authenticator)

The `Keukenmagazijn\PassportAuthenticator\Abstracts\ConcretePassportAuthenticator` code handles all the magic for your credentials. Let's make our own custom authenticator.

`app/Components/PassportAuthenticators/Instances/ExampleAuthenticator.php`:

```
