User authentication by domain
PHP
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Cache
DependencyInjection
EventListener
Resources/config
Security
Tests
User
.atoum.php
.gitignore Initial commit Jan 2, 2014
.travis.yml
LICENSE
M6WebDomainUserBundle.php
README.md
composer.json

README.md

DomainUserBundle Build Status

DomainUserBundle provides user authentication by subdomain. It allows firewalling, cache customization, route filtering and data filtering by subdomain.

Dependency

DomainUserBundle requires FirewallBundle.

Installation

Add this line in your composer.json:

{
    "require": {
        "m6web/domain-user-bundle": "~1.0"
    }
}

Update your vendors:

$ composer update m6web/domain-user-bundle

Add to your AppKernel.php:

new M6Web\Bundle\DomainUserBundle\M6WebDomainUserBundle(),
new M6Web\Bundle\FirewallBundle\M6WebFirewallBundle(),

Configuration

Modify your routes to add a parameter in your host requirement:

routes:
    resource: api_routing.yml
    host:     {client}api.example.com
    requirements:
        client: ([a-z0-9]+\.)?
    defaults:
        client ""

Add in your app/config.yml:

m6_web_domain_user:
    default_cache:    300      # Default cache duration
    router_parameter: client   # Parameter in the host requirement
    default_user:     public   # User when the parameter is not found
    users_dir:        %kernel.root_dir%/config/users # Directory containing the user configs
    firewall:
        allow_debug_route: false # Allows or not (default) web debug toolbar routes for the concerned environment

Add a user app/config/users/public.yml:

firewall:
    user_access: # Configure IP restrictions with FirewallBundle
        default_state: false
        lists:
            internal: true

    allow: # Filter routes alllowed to this user
        default: true
        methods:
            delete: false # Override by method
        resources:
            article: false # Override by routes configured with "defaults: {resource: article}"
        route:
            post_comment: false # Override by route name
        allow_debug_route: false # Allows or not (default) web debug toolbar routes for this user

cache:
    defaults: 60 # Override the default cache duration
    routes:
        hello: 86400 # Override by route name

entities:
    article:
        active: true # Arbitrary flag you can use to filter your entities in your repositories
parameters:
    param_name: param_value # Arbitrary parameters

Edit your app/config/security.yml:

security:
    firewalls:
        secured_area:
            pattern:            ^/
            anonymous:          false
            m6_web_domain_user: true

    providers:
        m6_web_domain_user:
            id: m6_web_domain_user.user_provider

Tests

$ ./vendor/bin/atoum

Credits

Developped by the Cytron Team of M6 Web. Tested with atoum.

License

DomainUserBundle is licensed under the MIT license.