ecmxperts/lumenoauth2

The EcmXperts LumenOauth2 package
185
Install
composer require ecmxperts/lumenoauth2
Latest Version:0.3.2
PHP:^7.2
Laravel:6
License:MIT
Last Updated:Oct 13, 2021
Links: GitHub  ·  Packagist
Maintainer: ecmXperts

LumenOauth2

Introduction

Lumen Oauth2 provides a simple API to authenticate your Lumen api with an Openid/Oauth2 server.

Installation

Via composer

Run composer require ecmxperts/lumenoauth2 0.*

Usage

In your .env add the following Environment Variable

IDENTITY_URL=openid/oauth2 server address

In your app\Providers\AuthServiceProvider.php inside the boot method add the following lines

$this->app['auth']->viaRequest('api', function ($request) {
    if (($token = $request->bearerToken()) != null) {
        try {
            return LumenOauth2::setProviderUrl(env('IDENTITY_URL'))
                ->setAudience('expected audience')
                ->authenticate($token);
        } catch (LumenOauth2Exception $e) {
            Log::error($e, ['exception' => $e]);
        }
    }
});

See Lumen Authentication for the rest on Authentication

The following methods can be used to access the authenticated user properties:

  • The global identifier for the user.
    $userGuid = Auth::user()->guid();

    $userGuid = $request->user()->guid();
  • The firstname for the user.
    $firstname = Auth::user()->firstname();

    $firstname = $request->user()->firstname();
  • The surname for the user.
    $surname = Auth::user()->surname();

    $surname = $request->user()->surname();
  • The fullname for the user.
    $fullname = Auth::user()->fullname();

    $fullname = $request->user()->fullname();
  • The tenant global identifier for the user.
    $tenant = Auth::user()->tenant();

    $tenant = $request->user()->tenant();

Related Packages

doctrine/dbal

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

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

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

423,477,751 607
nunomaduro/collision

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

403,217,078 4,664

Version History

Version Released PHP Laravel License
0.3.2 ^7.2 ^6.0 MIT