2017 © Pedro Peláez
 

library ght-api-authenticator-bundle

GHT API Authenticator Bundle

image

greenhollowtech/ght-api-authenticator-bundle

GHT API Authenticator Bundle

  • Thursday, May 19, 2016
  • by iisisrael
  • Repository
  • 0 Watchers
  • 0 Stars
  • 18 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

GHT API Authenticator Bundle

This bundle provides the GHT API Authenticator as a service in Symfony., (*1)

Installation

Get the Composer package

To install with Composer, run composer require greenhollowtech/ght-api-authenticator-bundle. For Symfony 2, make sure to stipulate the version ~1.0., (*2)

Add the GHTApiAuthenticatorBundle to your Symfony application

// app/AppKernel.php

    public function registerBundles()
    {
        return array(
            // ...
            new GHT\ApiAuthenticatorBundle\GHTApiAuthenticatorBundle(),
            // ...
        );
    }

Usage

Set up your firewall to use the API Authenticator., (*3)

# app/config/security.yml

security:
    ...
    firewalls:
        api:
            stateless: true
            simple_preauth:
                authenticator: ght_api_authenticator

Add the apiKey and apiSecret properties to your user entity, along with the related getters and setters., (*4)

If you already have properties established, and wish to use the existing data, simply configure the API Authenticator to use those properties instead of the default:, (*5)

# app/config/config.yml

ght_api_authenticator:
    user_entity:
        api_key_property: myKeyPropertyName
        api_secret_property: mySecretPropertyName

Custom User Provider

If your application has alternative means of loading the current user, you can provide that to the API Authenticator as well by defining your own service. Your custom user provider is passed as the third argument in the construct., (*6)

# src/AcmeBundle/Resources/config/services.yml

services:
    ...
    acme_api_user_authenticator:
        class: GHT\ApiAuthenticatorBundle\Security\ApiUserAuthenticator
        arguments:
            - %ght_api_authenticator.user_entity.api_key_property%
            - %ght_api_authenticator.user_entity.api_secret_property%
            - "@acme_custom_user_provider"

Then set the authenticator in your firewall to use this new service instead., (*7)

The Versions