2017 © Pedro Peláez
 

symfony-bundle auto-login-bundle

Authenticate users in your Symfony app via a single query parameter (e.g. email and newsletter links).

image

jmikola/auto-login-bundle

Authenticate users in your Symfony app via a single query parameter (e.g. email and newsletter links).

  • Thursday, March 15, 2018
  • by jmikola
  • Repository
  • 7 Watchers
  • 79 Stars
  • 109,376 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 13 Forks
  • 6 Open issues
  • 10 Versions
  • 6 % Grown

The README.md

JmikolaAutoLoginBundle

This bundle integrates the AutoLogin library with Symfony, which implements a security firewall listener to authenticate users based on a single query parameter. This is useful for providing one-click login functionality in email and newsletter links., (*1)

Installation

The bundle is published as a package and is installable via Composer:, (*2)

$ composer require jmikola/auto-login-bundle=^2.0

Activate the bundle in your application kernel:, (*3)


class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Jmikola\AutoLoginBundle\JmikolaAutoLoginBundle(), // ... ); } }

Compatibility

This bundle requires Symfony 4.3 or above., (*4)

Usage and Configuration

You need to create a new UserProvider service that implements Jmikola\AutoLogin\User\AutoLoginUserProviderInterface. This service is responsible for resolving the URL token to a user object., (*5)

This bundle registers a firewall listener, which is configured via the jmikola_auto_login key in your security component's firewall configuration. See this example configuration:, (*6)

# services.yml
services:
  acme.auto_login_user_provider:
    # Implements Jmikola\AutoLogin\User\AutoLoginUserProviderInterface
    class: Acme\UserBundle\Security\AcmeAutoLoginUserProvider
# security.yml
security:
  firewalls:
    main:
      # We need not specify a "provider" for our firewall or listeners,
      # since SecurityBundle will default to the first provider defined.
      jmikola_auto_login:
        auto_login_user_provider: acme.auto_login_user_provider

In the example above, we specify a custom service for auto_login_user_provider since the default EntityUserProvider does not implement AutoLoginUserProviderInterface., (*7)

When visiting http://example.com/path?_al=foobar, AcmeAutoLoginUserProvider::loadUserByAutoLoginToken() will be invoked with the value "foobar". This method should resolve that value to a user object or throw a Jmikola\AutoLogin\Exception\AutoLoginTokenNotFoundException., (*8)

Listener Options

The AutoLoginFactory defines the following listener options:, (*9)

  • auto_login_user_provider: AutoLoginUserProviderInterface service, which provides a method to load users by an auto-login token (i.e. query parameter). If this service is not defined, the listener's user provider will be used by default and an exception will be thrown if the provider does not implement the required interface (in addition to UserProviderInterface).
  • provider: User provider key. This is a standard option for most security listeners. If undefined, the default user provider for the firewall is used (see: SecurityBundle documentation).
  • token_param: The query parameter to be checked for an auto-login token. The presence of this query parameter will determine if the auto-login listener attempts authentication. In that respect, it is similar to the check_path option for the form-login listener. If undefined, the option defaults to _al.
  • override_already_authenticated: Boolean option determines whether an auto-login token should override an existing, authenticated session. This option defaults to false.

Alternative Configuration Example

In this example, we specify a provider that implements both Symfony\Component\Security\Core\User\UserProviderInterface and Jmikola\AutoLogin\User\AutoLoginUserProviderInterface. We also customize the URL parameter to use "auto_login" instead of the default "_al":, (*10)

# services.yml
services:
  acme.versatile_user_provider:
    # This class implements UserProviderInterface and
    # AutoLoginUserProviderInterface
    class: Acme\UserBundle\Security\VersatileUserProvider
# security.yml
security:
  providers:
    acme_user_provider:
      id: acme.versatile_user_provider
  firewalls:
    main:
      jmikola_auto_login:
        token_param: auto_login
        # We need not configure the auto_login_user_provider option here, as the
        # bundle will default to the firewall's default user provider, which
        # implements the necessary interface.

FOSUserBundle Configuration Example

If you are using FOSUserBundle, defining a service ID for your user provider will look familiar. You can easily integrate this bundle with FOSUserBundle by defining a custom service for fos_user.user_manager:, (*11)

services:
    acme.user_manager:
        # This class extends the appropriate UserManager from FOSUserBundle
        # and implements Jmikola\AutoLogin\User\AutoLoginUserProviderInterface
        class: Acme\UserBundle\Model\UserManager
        # Note: the remaining service configuration is abridged

fos_user:
    service:
        user_manager: acme.user_manager

The Versions

17/08 2015

v1.1.1

1.1.1.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login

24/01 2015

v1.1.0

1.1.0.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login

17/07 2013

v1.0.3

1.0.3.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login

06/06 2013

v1.0.2

1.0.2.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login

19/03 2013

v1.0.1

1.0.1.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login

26/02 2013

v1.0.0

1.0.0.0 https://github.com/jmikola/JmikolaAutoLoginBundle

Authenticate users in your Symfony2 app via a single query parameter (e.g. email and newsletter links).

  Sources   Download

MIT

The Requires

 

authentication security login auto-login