PHPackages                             sonrac/lumen-league-oauth2 - 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. sonrac/lumen-league-oauth2

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

sonrac/lumen-league-oauth2
==========================

Lumen league oauth2 wrapper

1.3.1(7y ago)3751MITPHPPHP &gt;=7.0

Since Oct 2Pushed 6y ago1 watchersCompare

[ Source](https://github.com/sonrac/lumen-oauth2)[ Packagist](https://packagist.org/packages/sonrac/lumen-league-oauth2)[ RSS](/packages/sonrac-lumen-league-oauth2/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (8)Versions (26)Used By (0)

[![Build Status](https://camo.githubusercontent.com/1d7f91eda593e62813d40d2101145f3bc3e7846f75171848a187450634cbe3fc/68747470733a2f2f7472617669732d63692e6f72672f736f6e7261632f6c756d656e2d6f61757468322e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/sonrac/lumen-oauth2)[![StyleCI](https://camo.githubusercontent.com/4c597fec7fcdbe6359ade5b99c7ee6aeaeae5dc0be9882982850a5ce3ddc19d9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3130353332323837332f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://styleci.io/repos/105322873)

[![Scrutinizer Build](https://camo.githubusercontent.com/5e0920ec689aee0547dea36549cf2825a74bcecc60ebfe5675981d71fd9cb40d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f6275696c642e706e673f623d6d6173746572)](https://camo.githubusercontent.com/5e0920ec689aee0547dea36549cf2825a74bcecc60ebfe5675981d71fd9cb40d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f6275696c642e706e673f623d6d6173746572)[![Scrutinizer](https://camo.githubusercontent.com/28e328322aeb374a084ea35c6d00e5fec8b00e86f034b6e8e3ce829ef1ac96b4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://camo.githubusercontent.com/28e328322aeb374a084ea35c6d00e5fec8b00e86f034b6e8e3ce829ef1ac96b4/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)[![Scrutinizer Code Coverage](https://camo.githubusercontent.com/a3f7d00048b5f7a91ce49d9f0e85a83d1f8042119db4c221d4a6cf42719983ed/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://camo.githubusercontent.com/a3f7d00048b5f7a91ce49d9f0e85a83d1f8042119db4c221d4a6cf42719983ed/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736f6e7261632f6c756d656e2d6f61757468322f6261646765732f636f7665726167652e706e673f623d6d6173746572)[![codecov](https://camo.githubusercontent.com/8c4860a2865d0e5d5fe6faf358031a228275e8ffcb25d0a4965e914d1d91f67d/68747470733a2f2f636f6465636f762e696f2f67682f736f6e7261632f6c756d656e2d6f61757468322f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/sonrac/lumen-oauth2)[![Packagist](https://camo.githubusercontent.com/b998c06f5204872d2d3b812da3c5809dfd37bafc2926b2c52399ecbc053fd614/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f762f737461626c652e737667)](https://camo.githubusercontent.com/b998c06f5204872d2d3b812da3c5809dfd37bafc2926b2c52399ecbc053fd614/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f762f737461626c652e737667)[![Latest Unstable Version](https://camo.githubusercontent.com/99f9311747fc2c430e1c5f342a49ced1b42b810be8c94095818d4e0bc3ba2c24/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f762f756e737461626c65)](https://packagist.org/packages/sonrac/lumen-league-oauth2)[![License](https://camo.githubusercontent.com/f45d904953153ca304a2328243d2733e095eee13a631a1f390709885d41dd692/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2f6672616d65776f726b2f6c6963656e73652e737667)](https://camo.githubusercontent.com/f45d904953153ca304a2328243d2733e095eee13a631a1f390709885d41dd692/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2f6672616d65776f726b2f6c6963656e73652e737667)[![VersionEYE](https://camo.githubusercontent.com/80924b3f5da6f9391cb96497930a3110edbf18358e780060e246b289d7b0e06d/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3539643630626563333638623038363466313531643138632f62616467652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/80924b3f5da6f9391cb96497930a3110edbf18358e780060e246b289d7b0e06d/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3539643630626563333638623038363466313531643138632f62616467652e7376673f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/519ba83f9aa9f2dac93d735d88798102cad8a5e8b1179453eda4d5f03001eab5/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f646f776e6c6f616473)](https://packagist.org/packages/sonrac/lumen-league-oauth2)[![Monthly Downloads](https://camo.githubusercontent.com/2882791799629c62ffec34d91614a18426c66b300471866b475afdb795193f55/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f642f6d6f6e74686c79)](https://packagist.org/packages/sonrac/lumen-league-oauth2)[![Daily Downloads](https://camo.githubusercontent.com/8197638000f2ee4a71adcdc5db65bf61c1244e142322715bc02de5cb2b16496f/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f642f6461696c79)](https://packagist.org/packages/sonrac/lumen-league-oauth2)[![composer.lock](https://camo.githubusercontent.com/3e7aa1b08504557e27d7b8705bd10e4b7c49078539dd2bc4831781800cc746cf/68747470733a2f2f706f7365722e707567782e6f72672f736f6e7261632f6c756d656e2d6c65616775652d6f61757468322f636f6d706f7365726c6f636b)](https://packagist.org/packages/sonrac/lumen-league-oauth2)

Installation
============

[](#installation)

```
composer require sonrac/lumen-league-oauth2
```

Usages
======

[](#usages)

Resister service provider first:

Add to your `bootstrap/app.php`

```
$app->register(\sonrac\lumenRest\Oauth2ServiceProvider::class);
```

Description
===========

[](#description)

`league/oauth2 -server` implementation for lumen

Contracts
=========

[](#contracts)

Contracts or oauth2 server implemented in `sonrac\lumenRest\Oauth2ServiceProvider`

Events
======

[](#events)

Events usages described in [official documentation](https://oauth2.thephpleague.com/authorization-server/events/)

Middleware
==========

[](#middleware)

Use `League\OAuth2\Server\Middleware\ResourceMiddleware` for validate authentication request

Use `League\OAuth2\Server\Middleware\AuthorizationServerMiddleware` for user authenticate

Example routing
===============

[](#example-routing)

Get access token
----------------

[](#get-access-token)

```
$app->router->post('/access_token', function (\Psr\Http\Message\ServerRequestInterface $request,
                                              \Psr\Http\Message\ResponseInterface $response) use ($app) {

  /* @var \League\OAuth2\Server\AuthorizationServer $server */
  $server = $app->make(\League\OAuth2\Server\AuthorizationServer::class);

  try {

      // Try to respond to the request
      return $server->respondToAccessTokenRequest($request, $response);

  } catch (\League\OAuth2\Server\Exception\OAuthServerException $exception) {

      // All instances of OAuthServerException can be formatted into a HTTP response
      return $exception->generateHttpResponse($response);

  } catch (\Exception $exception) {

      // Unknown exception
      $body = new \Zend\Diactoros\Stream('php://temp', 'r+');
      $body->write($exception->getMessage());
      return $response->withStatus(500)->withBody($body);

  }
});
```

Authorize third-party clients (implicit &amp; auth code grants)
---------------------------------------------------------------

[](#authorize-third-party-clients-implicit--auth-code-grants)

```
$app->router->get('/authorize', function (\League\OAuth2\Server\AuthorizationServer $server,
                                          \Psr\Http\Message\ServerRequestInterface $request,
                                          \Psr\Http\Message\ResponseInterface $response) {
    try {
        // Validate the HTTP request and return an AuthorizationRequest object.
        $authRequest = $server->validateAuthorizationRequest($request);

        // The auth request object can be serialized and saved into a user's session.
        // You will probably want to redirect the user at this point to a login endpoint.

        // Once the user has logged in set the user on the AuthorizationRequest
        $authRequest->setUser(app()->make(\League\OAuth2\Server\Entities\UserEntityInterface::class)); // an instance of UserEntityInterface

        // At this point you should redirect the user to an authorization page.
        // This form will ask the user to approve the client and the scopes requested.

        // Once the user has approved or denied the client update the status
        // (true = approved, false = denied)
        $authRequest->setAuthorizationApproved(true);

        // Return the HTTP redirect response
        return $server->completeAuthorizationRequest($authRequest, $response);
    } catch (\Exception $exception) {

        // Unknown exception
        $body = new \Zend\Diactoros\Stream('php://temp', 'r+');
        $body->write($exception->getMessage());

        return $response->withStatus(500)->withBody($body);

    }
});
```

JWT guard
=========

[](#jwt-guard)

For using JWT token you need define JWT guard

Example config:

```
'defaults' => [
        'guard' => 'jwt'
    ],
    'guards' => [
        'jwt' => [
            'driver' => 'jwt',
            'provider' => 'clients',
        ],
        'user' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],
    'providers' => [
        'clients' => [
            'driver' => 'eloquent',
            'model' => app(\League\OAuth2\Server\Entities\ClientEntityInterface::class),
        ],
        'users' => [
            'driver' => 'eloquent',
            'model' => app(\League\OAuth2\Server\Entities\UserEntityInterface::class),
        ],
    ],
```

Generate keys
=============

[](#generate-keys)

For using SSL encryption generate keys first:

```
php artisan generate:keys
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Recently: every ~30 days

Total

23

Last Release

2791d ago

Major Versions

0.3.3 → 1.02018-07-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/1245037f65b027a2c38d7aa0281cd04f53ac27eaf695a60da7311254fcc99350?d=identicon)[sonrac](/maintainers/sonrac)

---

Top Contributors

[![sonrac](https://avatars.githubusercontent.com/u/3766459?v=4)](https://github.com/sonrac "sonrac (54 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/sonrac-lumen-league-oauth2/health.svg)

```
[![Health](https://phpackages.com/badges/sonrac-lumen-league-oauth2/health.svg)](https://phpackages.com/packages/sonrac-lumen-league-oauth2)
```

###  Alternatives

[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k89.4M575](/packages/laravel-passport)[shopware/platform

The Shopware e-commerce core

3.4k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k16.8k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M524](/packages/shopware-core)[simplesamlphp/simplesamlphp-module-oidc

A SimpleSAMLphp module adding support for the OpenID Connect protocol

5017.7k1](/packages/simplesamlphp-simplesamlphp-module-oidc)[shopware/administration

Administration frontend for the Shopware Core

404.2M106](/packages/shopware-administration)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
