Skip to content

Latest commit

 

History

History
77 lines (58 loc) · 2.06 KB

authentication.md

File metadata and controls

77 lines (58 loc) · 2.06 KB

Security Authenticators

Based on Guard, many authenticators are available to set your authentication system.

Available authenticators

  • EmailAuthenticator: authenticate a user via its email only (given as query). Be sure to do only forget password features like.
  • TokenAuthenticator: expect a valid token

This 2 authenticator MUST be defined as stateless.

User model

The User model must implement Symfony\Component\Security\Core\User\UserInterface

User repository

The User repository must implement Biig\Component\User\Security\User\UserTokenProviderInterface

This is required only for TokenAuthentication.

Services definition

Define the authenticators you need in your services.yml file.

services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false

    Biig\Component\User\Security\Authenticator\BasicAuthenticator: ~
    Biig\Component\User\Security\Authenticator\EmailAuthenticator: ~
    Biig\Component\User\Security\Authenticator\TokenAuthenticator:
        $userRepository: '@App\Repository\UserRepository'

Configure the authenticators

Here is an example of configuration.

security:
    providers:
        user_provider:
            entity:
                class: App\Model\User
                property: email
    firewalls:
        login:
            pattern: ^/login
            anonymous: ~
            provider: user_provider
            http_basic: ~
            stateless: true

        reset_password:
            pattern: ^/reset-password
            anonymous: ~
            provider: user_provider
            stateless: true
            guard:
                authenticators:
                    - Biig\Component\User\Security\Authenticator\TokenAuthenticator

        forget_password:
            pattern: ^/forget-password
            anonymous: ~
            provider: user_provider
            stateless: true
            guard:
                authenticators:
                    - Biig\Component\User\Security\Authenticator\EmailAuthenticator