2017 © Pedro Peláez
 

contao-bundle contao-oauth2-bundle

ContaoOAuth2Bundle for Symfony with Contao

image

craffft/contao-oauth2-bundle

ContaoOAuth2Bundle for Symfony with Contao

  • Monday, January 29, 2018
  • by Craffft
  • Repository
  • 3 Watchers
  • 2 Stars
  • 20 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

Build Status, (*1)

Contao OAuth2 Bundle

Contao OAuth2 Bundle for Symfony, (*2)

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*3)

$ composer require craffft/contao-oauth2-bundle "~1.0"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*4)

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:, (*5)

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            // Add them all!
            new Contao\CoreBundle\HttpKernel\Bundle\ContaoModuleBundle('multicolumnwizard', $this->getRootDir()),
            new FOS\OAuthServerBundle\FOSOAuthServerBundle(),
            new Craffft\ContaoOAuth2Bundle\CraffftContaoOAuth2Bundle(),
        );

        // ...
    }

    // ...
}

Step 3: Config the Bundle

As next add the following configuration to the app/config/config.yml file of your project:, (*6)

# app/config/config.yml

# ...
# Doctrine configuration
doctrine:
    dbal:
        # ...
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# ...

# FOS OAuth2 Server Bundle
fos_oauth_server:
    db_driver: orm
    client_class:        Craffft\ContaoOAuth2Bundle\Entity\OAuth2Client
    access_token_class:  Craffft\ContaoOAuth2Bundle\Entity\OAuth2AccessToken
    refresh_token_class: Craffft\ContaoOAuth2Bundle\Entity\OAuth2RefreshToken
    auth_code_class:     Craffft\ContaoOAuth2Bundle\Entity\OAuth2AuthCode
    service:
        user_provider: craffft.contao_oauth2.user_provider

Import the routing.yml configuration file in app/config/routing.yml:, (*7)

# app/config/routing.yml

fos_oauth_server_token:
    resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml"

fos_oauth_server_authorize:
    resource: "@FOSOAuthServerBundle/Resources/config/routing/authorize.xml"

Copy the content of vendor/contao/core-bundle/src/Resources/config/security.yml file and replace app/config/security.yml file with it. Than amend it with the following code:, (*8)

# app/config/security.yml

# ...
security:
    encoders:
        Craffft\ContaoOAuth2Bundle\Entity\Member:
            id: craffft.contao_oauth2.contao_password_encoder

    firewalls:
        oauth_token:                                   # Everyone can access the access token URL.
            pattern: ^/oauth/v2/token
            security: false

        api:
            pattern: ^/api                             # All URLs are protected
            fos_oauth: true                            # OAuth2 protected resource
            stateless: true                            # Do no set session cookies
            anonymous: false                           # Anonymous access is not allowed

Step 4: Generate database tables

Change your database tables to InnoDB to prevent schema update errors., (*9)

ALTER TABLE tl_member ENGINE=InnoDB;
ALTER TABLE tl_oauth_client ENGINE=InnoDB;

Please update your database with the following command, because the contao install tool will not generate the symfony relevant tables., (*10)

php app/console doctrine:schema:update --force

The Versions