m6web/domain-user-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

User authentication by domain

v3.0.0 2019-11-27 13:41 UTC

This package is auto-updated.

Last update: 2022-03-27 14:02:35 UTC


README

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.