Symfony bundle which provides OAuth 2.0 authorization/resource server capabilities.
Clone or download

Trikoder OAuth 2 Bundle

Build Status Latest Stable Version License Code coverage

Symfony bundle which provides OAuth 2.0 authorization/resource server capabilities. The authorization and resource server actors are implemented using the thephpleague/oauth2-server library.

Important notes

This bundle provides the "glue" between thephpleague/oauth2-server library and Symfony. It implements thephpleague/oauth2-server library in a way specified by its official documentation. For implementation into Symfony project, please see bundle documentation and official Symfony security documentation.


This package is currently in the active development.


  • API endpoint for client authorization and token issuing
  • Configurable client and token persistance (includes Doctrine support)
  • Integration with Symfony's Security layer



  1. Require the bundle with Composer:

    composer require trikoder/oauth2-bundle --no-plugins --no-scripts

    NOTE: Due to required pre-configuration, this bundle is currently not compatible with Symfony Flex.

  2. Create the bundle configuration file under config/packages/trikoder_oauth2.yaml. Here is a reference configuration file:

            # Full path to the private key file.
            # How to generate a private key:
            private_key:    # Required, Example: /var/oauth/private.key
            # The string used as an encryption key.
            # How to generate an encryption key:
            encryption_key:    # Required
            # How long the issued access token should be valid for.
            # The value should be a valid interval:
            access_token_ttl: PT1H
            # How long the issued refresh token should be valid for.
            # The value should be a valid interval:
            refresh_token_ttl: P1M
            # Full path to the public key file
            # How to generate a public key:
            public_key:    # Required, Example: /var/oauth/public.key
        # Scopes that you wish to utilize in your application.
        # This should be a simple array of strings.
        scopes: []
        # Configures different persistence methods that can be used by the bundle for saving client and token data.
        # Only one persistence method can be configured at a time.
                # Name of the entity manager that you wish to use for managing clients and tokens.
                entity_manager: default # Required
            in_memory: ~
  3. Enable the bundle in config/bundles.php by adding it to the array:

    Trikoder\Bundle\OAuth2Bundle\TrikoderOAuth2Bundle::class => ['all' => true]
  4. Update the database so bundle entities can be persisted using Doctrine:

    bin/console doctrine:schema:update --force
  5. Import the routes inside your config/routes.yaml file:

        resource: '@TrikoderOAuth2Bundle/Resources/config/routes.xml'

You can verify that everything is working by issuing a GET request to the /token endpoint.



Docker 18.03+ and Docker Compose 1.13+ are required for the development environment.

Building the environment

Make sure your Docker images are all built and up-to-date using the following command:

dev/bin/docker-compose build

After that, install all the needed packages required to develop the project:

dev/bin/php composer install


You can run the test suite using the following command:

dev/bin/php composer test

Code linting

This bundle enforces the PSR-2 and Symfony code standards during development using the PHP CS Fixer utility. Before commiting any code, you can run the utility so it can fix any potential rule violations for you:

dev/bin/php composer lint


All the package releases are recorded in the CHANGELOG file.

Reporting issues

Use the issue tracker to report any issues you might have.


See the LICENSE file for license rights and limitations (MIT).