fabricekabongo/auth0-api-authentication-bundle

Integrate with Auth0 to bring API authentication to Symfony

v0.4.2 2017-03-24 20:32 UTC

README

Badges:

Codacy Badge

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:

$ composer require fabricekabongo/auth0symfonyapiauthenticator

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

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:

<?php
// app/AppKernel.php

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

            new FabriceKabongo\Auth0\APIAuthenticationBundle\APIAuthenticationBundle(),
        );

        // ...
    }

    // ...
}

Then, set the authenticator and provider to these values on app/config/security.yml:

# app/config/security.yml
security:
    # ...

    firewalls:
        secured_area:
            pattern: ^/youbaseurl
            stateless: true
            simple_preauth:
                authenticator: fabricekabongo.auth0.services.apikeyuserauthenticator
            provider: api_key_user_provider
            anonymous:    true

    providers:
        api_key_user_provider:
            id: fabricekabongo.auth0.services.apikeyuserprovider
     
    access_control:
        - { path: ^/youbaseurl, roles: ROLE_USER }
# app/config/config.yml
fabrice_kabongo_auth0_api_authentication_bundle:
    valid_audiences:
        - 'https://your.service.indentifier'
    authorized_iss:
        - 'https://youraccount.auth0.com'

See Auth0 APIs

Step 3: write functional Test for your API

Create a functional test and extend the FabriceKabongo\Auth0\APIAuthenticationBundle\Test\AuthenticatedWebTestCase In your test cases create a client and pass it to the setUpClient methods with the role you want the user to have

public function testMyOwnTestCase() 
{
    $client = $this->setUpClient(
        static::createClient(),
        ['ROLE_READ_PROFIL', 'ROLE_EDIT_PAYMENTINFO']
    );
    
    // do your http calls and do your test as usual
}

Step 4: Help me make this better and simpler. Please :)

Todo: Write unit test (how will I mock the JWS verifier) Todo: Create a new branch for other versions of Symfony (if works differently) Todo: Introduce awesome new features.

I love this project and will continue to work on it. Please do the same.