PHPackages                             borisguery/oauth2-server - 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. borisguery/oauth2-server

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

borisguery/oauth2-server
========================

0.1(10y ago)4283MITPHPPHP ~5.5|~7.0

Since Apr 4Pushed 10y ago1 watchersCompare

[ Source](https://github.com/borisguery/oauth2-server)[ Packagist](https://packagist.org/packages/borisguery/oauth2-server)[ RSS](/packages/borisguery-oauth2-server/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (2)Used By (3)

oauth2-server
=============

[](#oauth2-server)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e33456ee38f6d715ada3d4d4941ac6e1aa39519cd41a023ea30200f01a4d8270/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626f72697367756572792f6f61757468322d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/borisguery/oauth2-server)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/edf7abed76356cb0e102958adb585bec4deee4c349972314e966d678635cf90d/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f626f72697367756572792f6f61757468322d7365727665722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/borisguery/oauth2-server)[![Coverage Status](https://camo.githubusercontent.com/31464d0b1ae91a562f9c6e3ddb73d25bafc5eaf0778402fdd378035f4ff87809/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f626f72697367756572792f6f61757468322d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/borisguery/oauth2-server/code-structure)[![Quality Score](https://camo.githubusercontent.com/78429a575a05eeecb6a36112f081a4c1bde004ff9a15a12358b5b897bb0175cf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f626f72697367756572792f6f61757468322d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/borisguery/oauth2-server)[![Total Downloads](https://camo.githubusercontent.com/73225157f1e1f6871096a9124de82615271f17a4b409d55d453e7daf923158d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626f72697367756572792f6f61757468322d7365727665722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/borisguery/oauth2-server)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Install
-------

[](#install)

Via Composer

```
$ composer require borisguery/oauth2-server
```

Usage
-----

[](#usage)

```
class OAuht2Controller {

    public function tokenAction(Request $request)
    {
        $sfPasswordGrantType = new SymfonySecurityPasswordGrantType(
            $this->container->get('security.user_provider'),
            $this->container->get('security.encoder_factory')->getEncoder(UserAccount::class)
        );

        $clientStorage = new InMemoryClientStorage();
        $defaultClient = new Client(
            'test',
            null,
            [],
            ['password']
        );

        $clientStorage->save($defaultClient);

        $configuration = (new ResourceServerConfigurationBuilder())
            ->setAccessTokenStorage(new InMemoryAccessTokenStorage())
            ->setClientStorage($clientStorage)
            ->setRefreshStorage(new InMemoryRefreshTokenStorage())
            ->setAccessTokenGenerator(new Php7CSPRNGStringGenerator())
            ->addGrantType($sfPasswordGrantType)
            ->alwaysRequireAClient(true)
            ->alwaysGenerateARefreshToken(true)
            ->build()
            ->getResourceConfiguration()
        ;

        $resourceServer = new ResourceServer($configuration);

        $inputDataBag = SymfonyHttpFoundationRequestInputDataBagFactory::fromRequest($request);

        $attemptResult = $resourceServer->requestAccessToken(
            new TokenRequestAttempt($inputDataBag->getGrantType(), $inputDataBag)
        );

        if ($attemptResult instanceof SuccessfulTokenRequestAttemptResult) {
            $statusCode = 200;
            $response = [
                'access_token' => $attemptResult->getAccessToken()->getToken(),
                'expires_in'   => $attemptResult->getAccessToken()->getExpiresIn(),
                'token_type'   => $attemptResult->getAccessToken()->getTokenType(),
                'refresh_token' => $attemptResult->getRefreshToken()
                    ? $attemptResult->getRefreshToken()->getToken()
                    : null,
            ];
        } elseif ($attemptResult instanceof FailedTokenRequestAttemptResult) {
            $statusCode = 400;
            $response = [
                'error' => (string) $attemptResult->getGrantDecision()->getError(),
                'error_description' => $attemptResult->getGrantDecision()->getError()->getErrorDescription(),
                'error_uri' => $attemptResult->getGrantDecision()->getError()->getErrorUri(),
            ];
        }

        return new Response(json_encode($response), $statusCode, ['Content-Type' => 'application/json']);
    }
}
```

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Boris Guéry](https://github.com/borisguery)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

3732d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e697c30c60bfd1c329e9661645ba5a79dd62d6375e48656b9ba9eaf54fd59956?d=identicon)[borisguery](/maintainers/borisguery)

---

Top Contributors

[![borisguery](https://avatars.githubusercontent.com/u/345495?v=4)](https://github.com/borisguery "borisguery (25 commits)")

---

Tags

oauthoauth2

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/borisguery-oauth2-server/health.svg)

```
[![Health](https://phpackages.com/badges/borisguery-oauth2-server/health.svg)](https://phpackages.com/packages/borisguery-oauth2-server)
```

###  Alternatives

[league/oauth2-server

A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.

6.7k143.0M272](/packages/league-oauth2-server)[league/oauth2-client

OAuth 2.0 Client Library

3.8k125.2M1.3k](/packages/league-oauth2-client)[bshaffer/oauth2-server-php

OAuth2 Server for PHP

3.3k15.8M112](/packages/bshaffer-oauth2-server-php)[hwi/oauth-bundle

Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony.

2.4k22.0M76](/packages/hwi-oauth-bundle)[knpuniversity/oauth2-client-bundle

Integration with league/oauth2-client to provide services

84217.7M77](/packages/knpuniversity-oauth2-client-bundle)[friendsofsymfony/oauth2-php

OAuth2 library

51618.2M21](/packages/friendsofsymfony-oauth2-php)

PHPackages © 2026

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