Giter Site home page Giter Site logo

snipiba / oc-passwordless-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pageballoon/oc-passwordless-plugin

0.0 0.0 0.0 22 KB

OctoberCMS plugin for passwordless authentication

Home Page: http://octobercms.com/plugin/nocio-passwordless

License: MIT License

PHP 92.76% HTML 7.24%

oc-passwordless-plugin's Introduction

This plugin brings passwordless user authentication to OctoberCMS (the WinterCMS version can be found here). Instead of filling username and password, frontend users provide their email address and receive a link with login token that registers and authenticates them on the site. Passwordless authentication is secure and can greatly improve the user experience as it simplifies the registration and login process where many users dread having to fill out forms and go through a rigorous registration process.

Features

  • Works well with Rainlab.User plugin as well as custom authentication systems
  • Login tokens are valid only once and expire after 30 minutes for increased security while being automatically cleaned from the system
  • Supports redirection after login
  • Optional JSON API to consume user details
  • Open source to allow and encourage security inspection
  • Developer friendly and highly customizable
  • Includes a cookie-token authentication method that can minimize repeated logins

Additional information

In future, the plugin might be extended to allow for

  • Option to allow for change of email
  • Improved JSON API
  • Support stateless JWT-based authentication
  • Backend logins
  • ...

If you find this plugin useful, please consider donating to support its further development.


The plugin provides an Account component that is similiar to Rainlab.User's account component.

The Account component

The account component provides the main functionality and can be included in any CMS page that should serve as login endpoint.

The Account component has the following properties:

  • model - [string] specifies the user model the form authenticates (must have an email field). Defaults to Rainlab\User\Models\User
  • auth - [string] specifies a class of facade that manages the authentication state (see below). Defaults to Rainlab\User\Facades\Auth
  • mail_template [string] the email template of the login mail. Defaults to nocio.passwordless::mail.login
  • redirect [dropdown] specifies a page name to redirect to after sign in (can be overwritten, see below)
  • allow_registration - [checkbox] if disabled, only existing users can request a login
  • api - [checkbox] if enabled, the component will expose an API endpoint ?api to query the authentication status

The component will display the email login form and -- if the user is logged in -- display account information. Note that the component requires the ajax framework to work.

The authentication manager

The authentication manager that can be specified in the Account component is a class or facade that manages the user authentication through a standardised API:

  • login($user) {} - signs in $user
  • check() {} - checks whether user is authenticated (returns boolean)
  • getUser() {} - returns the authenticated user or null if not authenticated
  • logout() {} - logs the user out

Available auth managers:

Rainlab\User\Facades\Auth

Auth manager provided by the Rainlab.User plugin.

Nocio\Passwordless\Classes\CookieTokenAuth

Auth manager that stores authentication state as token in a httpOnly cookie. The user stays authenticated until the cookie is deleted or the token expires. The manager can be used as middleware to protect endpoints that require authentication. The authentication method is particuarly useful for RESTful APIs. Note that the cookie will only be transfered via secure https connections. If you want to allow http connections you can set COOKIE_TOKEN_SECURE=true in the .env file.

Custom manager

To cater for custom authentication mechanism you can implement your own auth manager that exhibits the given API. If you implemented an auth manager that could be useful to others please consider contributing it in a pull request.

Return redirections

The Account manager can process GET redirect requests after login, e.g. ?redirect=/awesome/redirect/url. This can be useful to improve the user expirience in the case in which an unauthenticated user accesses a page that requires authentication and is being redirected to the login page. Using GET, the original request location can be stored for after login so that the user is automatically redirected to the page she originally intended to access. Note that GET-redirects overwrite the redirection behaviour that can be defined in the component settings.

JSON API

If enabled, the Account component exposes and JSON API endpoint that can be consumed by an authenticated user (unauthenticated users will face an 401 Unauthorized. response). Currently, the only route is ?api=info which returns the jsonified user model.

Developer API

The plugin provides a token model Nocio\Passwordless\Models\Token that can be re-used by developers to implement token management. The model provides two main functions:

  • generate($user, $expires = 10, $scope = 'default') which returns a token for a given $user model object (or more general the token payload). Make sure to specificy a custom scope, e.g. myplugin to avoid scope collision.
  • parse($raw_token, $delete = false, $scope = null) which parses (and optionally $deletes) a provided $raw_token in a given $scope and returns the correspoding $user model. It raises an ApplicationException if the token is expired, invalid or cannot be parsed.

More details can be found in the model class documentation.

Support & Contribution

I can only offer limited support but will try to answer questions and feature requests on GitHub. I am also happy to accept pull requests, especially for the missing features list on the Plugin details page.

Please consider donating to support the ongoing development if you find this plugin useful.

oc-passwordless-plugin's People

Contributors

frthjf avatar snipiba avatar massimomegistus avatar gergo85 avatar

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.