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

Installs: 118 395

Dependents: 8

Suggesters: 0

Security: 0

Stars: 174

Watchers: 19

Forks: 76

Open Issues: 39


v3.1.1 2020-04-10 16:45 UTC


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 and a PSR 7/17 implementation with Composer:

    composer require trikoder/oauth2-bundle nyholm/psr7

    If your project is managed using Symfony Flex, the rest of the steps are not required. Just follow the post-installation instructions instead! 🎉

    NOTE: This bundle requires a PSR 7/17 implementation to operate. We recommend that you use nyholm/psr7. Check out this document if you wish to use a different implementation.

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

        authorization_server: # Required
            # Full path to the private key file.
            # How to generate a private key:
            private_key:          ~ # Required, Example: /var/oauth/private.key
            # Passphrase of the private key, if any
            private_key_passphrase: null
            # The plain string or the ascii safe string used to create a Defuse\Crypto\Key to be used as an encryption key.
            # How to generate an encryption key:
            encryption_key:       ~ # Required
            # The type of value of 'encryption_key'
            encryption_key_type:  plain # One of "plain"; "defuse"
            # 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
            # How long the issued auth code should be valid for.
            # The value should be a valid interval:
            auth_code_ttl:        PT10M
            # Whether to enable the client credentials grant
            enable_client_credentials_grant: true
            # Whether to enable the password grant
            enable_password_grant: true
            # Whether to enable the refresh token grant
            enable_refresh_token_grant: true
            # Whether to enable the authorization code grant
            enable_auth_code_grant: true
            # Whether to require code challenge for public clients for the auth code grant
            require_code_challenge_for_public_clients: true
            # Whether to enable the implicit grant
            enable_implicit_grant: true
        resource_server:      # Required
            # 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.
        persistence:          # Required
                # Name of the entity manager that you wish to use for managing clients and tokens.
                entity_manager:       default
            in_memory:            ~
        # The priority of the event listener that converts an Exception to a Response
        exception_event_listener_priority: 10
        # Set a custom prefix that replaces the default 'ROLE_OAUTH2_' role prefix
        role_prefix:          ROLE_OAUTH2_
  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 POST request to the /token endpoint.

❮ NOTE ❯ It is recommended to control the access to the authorization endpoint so that only logged in users can approve authorization requests. You should review your security.yml file. Here is a sample configuration:

        - { path: ^/authorize, roles: IS_AUTHENTICATED_REMEMBERED }



Please see CONTRIBUTING for details.


This project adheres to Semantic Versioning 2.0.0. Randomly breaking public APIs is not an option.

However, starting with version 4, we only promise to follow SemVer on structural elements marked with the @api tag.


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).