Giter VIP home page Giter VIP logo

autologin's Introduction

AutoLogin

This library implements a Symfony 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.

Installation

The library is published as a package and is installable via Composer:

$ composer require jmikola/auto-login

Compatibility

This library requires Symfony 4.3 or above.

Usage

This library implements authentication provider and firewall listener classes, which may be plugged into Symfony's security component to intercept requests and automatically authenticate users based on a single request parameter.

To utilize this library in a full-stack Symfony application, you may want to use JmikolaAutoLoginBundle. An example of registering an authentication provider and firewall listener manually may be found in the Security component documentation.

Token

When a user is automatically logged in by a token parameter in the request, they will be authenticated with an AutoLoginToken instance. In the context of authorization, this token satisfies IS_AUTHENTICATED_FULLY. Ideally, it would be possible to restrict the token to IS_AUTHENTICATED_REMEMBERED, but that is not yet supported. Additional information on these authorization levels may be found in Symfony's authorization documentation.

Events

The firewall listener may dispatch events if constructed with an event dispatcher instance.

Interactive Login

Upon successful authentication by a token parameter in the request, an interactive login core event will be dispatched with the authenticated AutoLoginToken instance.

Already Authenticated

This event was contributed by Antonio Trapani in PR #9.

If a token parameter is present in the request, but the user is already authenticated, a custom event will be dispatched, which includes the token's value. After dispatching this event, the listener's default behavior is to return immediately, since there is likely no work to be done.

A practical use for this event would be to mark a user's email addresses as confirmed, assuming the auto-login link with the token was only delivered via email. As a business requirement, the confirmation service might also listen to the interactive login core event and operate when the authenticated token was an AutoLoginToken instance.

Note: Unlike the interactive login event, the token parameter in this event will not have been validated. It will be the responsibility of the listener to check whether it matches the currently authenticated user. For this reason, it may be helpful to inject this library's provider class.

Overriding Already Authenticated Users

This feature was contributed by Mathieu Gauthier-Lafaye in PR #10.

By default, the listener will only dispatch an event if the user is already authenticated; it does not override the existing authenticated user. In some cases, it may be desirable to allow an auto-login link to override an existing authenticated user. Otherwise, the user would first need to log out before using the auto-login link. Setting the listener's override_already_authenticated boolean option to true will enable this behavior.

autologin's People

Contributors

bocharsky-bw avatar espritf avatar fran6co avatar henrikbjorn avatar jmikola avatar lenar avatar pborreli avatar rasmustnilsson avatar reflex14 avatar stof avatar svetlinstaev avatar twistedlogic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autologin's Issues

Documentation

Can you provide a documentation of your bundle ?
Many thanks before

Upgrade dependencies

The versions for PHP and the Symfony components are quite outdated. They are also not supported anymore. With the arrival of Symfony 3 this library (and it's bundle) can not be installed anymore.

I'm willing to work on a PR for this, in which I also up the version requirements to PHP 5.5.9 (in line with Symfony, and PHP 5.5 will be EOL in 6 months), and Symfony 2.7 and up. Symfony 2.3 is still maintained for a couple of months, but I think a next major release can set stricter requirements. Older Symfony projects can just use an older version imo.

I wanted your thoughts before starting to work on this though.

Fallback?

Hi,

I understand that I can configure this on any existing firewall. My question then is: if the request doesn't have the parameter or the parameter is somehow invalid, will it fallback to form login logic?

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.