happyr/auth0-bundle

Symfony integration with auth0

Fund package maintenance!
Nyholm

Installs: 9 526

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 1

Forks: 5

Open Issues: 0

Type:symfony-bundle

0.7.0 2020-12-01 12:35 UTC

This package is auto-updated.

Last update: 2020-12-01 14:49:13 UTC


README

Latest Version Software License Total Downloads

Installation

Install with Composer:

composer require happyr/auth0-bundle auth0/auth0-php:@alpha

Enable the bundle in bundles.php

return [
    // ...
    Happyr\Auth0Bundle\HappyrAuth0Bundle::class => ['all' => true],
];

Add your credentials:

// config/packages/happyr_auth0.yml
happyr_auth0:
    domain: '%env(AUTH0_DOMAIN)%'
    login_domain: '%env(AUTH0_LOGIN_DOMAIN)%'
    client_id: '%env(AUTH0_CLIENT_ID)%'
    client_secret: '%env(AUTH0_SECRET)%'
    cache: 'cache.redis'
    scope: openid profile email # "openid" is required.
    # If you want to configure firewall, then this section is required
    firewall:
        check_route: default_login_check
        failure_path: default_logout
        default_target_path: user_dashboard

Configure your application's security:

// config/packages/security.yml
security:
    enable_authenticator_manager: true # Use the new authentication system
    providers:
        users:
            entity:
                class: 'App\Entity\User'
                property: 'auth0Id'

    firewalls:
        default:
            pattern:  ^/.*

            entry_point: auth0.entry_point
            custom_authenticators:
                - auth0.authenticator

            logout:
                path: default_logout
                target: _user_logout
                invalidate_session: true

Custom user provider

If you want to use a custom user provider that fetches a user with more data than just the Auth0 id, then you may create a service that implement Happyr\Auth0Bundle\Security\Auth0UserProviderInterface.

Then configure the bundle to use that service:

// config/packages/happyr_auth0.yml
happyr_auth0:
    # ...

    firewall:
        # ..
        user_provider: App\UserProvider\Auth0UserProvider

Troubleshooting

Make sure you have csrf_protection enabled.

framework:
    csrf_protection:
        enabled: true