All Projects → bigpresh → Dancer Plugin Auth Extensible

bigpresh / Dancer Plugin Auth Extensible

Authentication framework for Dancer-based web applications

Programming Languages

perl
6916 projects

Projects that are alternatives of or similar to Dancer Plugin Auth Extensible

Fosite
Extensible security first OAuth 2.0 and OpenID Connect SDK for Go.
Stars: ✭ 1,738 (+7800%)
Mutual labels:  hacktoberfest, authentication, authorization
Laravel Acl
This package helps you to associate users with permissions and permission groups with laravel framework
Stars: ✭ 404 (+1736.36%)
Mutual labels:  hacktoberfest, authentication, authorization
Product Is
Welcome to the WSO2 Identity Server source code! For info on working with the WSO2 Identity Server repository and contributing code, click the link below.
Stars: ✭ 435 (+1877.27%)
Mutual labels:  hacktoberfest, authentication, authorization
Yosai
A Security Framework for Python applications featuring Authorization (rbac permissions and roles), Authentication (2fa totp), Session Management and an extensive Audit Trail
Stars: ✭ 582 (+2545.45%)
Mutual labels:  authentication, authorization
Doorkeeper
Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape.
Stars: ✭ 4,917 (+22250%)
Mutual labels:  authentication, authorization
Wetech Admin
wetech-admin是基于Spring Boot 2.0+Mybatis+Vue的轻量级后台管理系统,适用于中小型项目的管理后台,支持按钮级别的权限控制,系统具有最基本的用户管理、角色管理、权限管理等通用性功能,企业或个人可直接在此基础上进行开发,扩展,添加各自的需求和业务功能!
Stars: ✭ 570 (+2490.91%)
Mutual labels:  authentication, authorization
Cloudfront Auth
An AWS CloudFront [email protected] function to authenticate requests using Google Apps, Microsoft, Auth0, OKTA, and GitHub login
Stars: ✭ 471 (+2040.91%)
Mutual labels:  authentication, authorization
Aspnet5identityserverangularimplicitflow
OpenID Connect Code / Implicit Flow with Angular and ASP.NET Core 5 IdentityServer4
Stars: ✭ 670 (+2945.45%)
Mutual labels:  authentication, authorization
Social Core
Python Social Auth - Core
Stars: ✭ 618 (+2709.09%)
Mutual labels:  authentication, authorization
Php Auth
Authentication for PHP. Simple, lightweight and secure.
Stars: ✭ 713 (+3140.91%)
Mutual labels:  authentication, authorization
Auth0.js
Auth0 headless browser sdk
Stars: ✭ 755 (+3331.82%)
Mutual labels:  authentication, authorization
Awesome Auth
📊 Software and Libraries for Authentication & Authorization
Stars: ✭ 520 (+2263.64%)
Mutual labels:  authentication, authorization
Steam
☁️ Python package for interacting with Steam
Stars: ✭ 489 (+2122.73%)
Mutual labels:  hacktoberfest, authentication
Angular Auth Oidc Client
npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow
Stars: ✭ 577 (+2522.73%)
Mutual labels:  hacktoberfest, authentication
Cerberus
A demonstration of a completely stateless and RESTful token-based authorization system using JSON Web Tokens (JWT) and Spring Security.
Stars: ✭ 482 (+2090.91%)
Mutual labels:  authentication, authorization
Fwknop
Single Packet Authorization > Port Knocking
Stars: ✭ 664 (+2918.18%)
Mutual labels:  authentication, authorization
Aws Serverless Auth Reference App
Serverless reference app and backend API, showcasing authentication and authorization patterns using Amazon Cognito, Amazon API Gateway, AWS Lambda, and AWS IAM.
Stars: ✭ 724 (+3190.91%)
Mutual labels:  authentication, authorization
Pizzly
The simplest, fastest way to integrate your app with an OAuth API 😋
Stars: ✭ 796 (+3518.18%)
Mutual labels:  hacktoberfest, authentication
Jso
Easy to use OAuth 2.0 javascript library for use in your javascript application.
Stars: ✭ 830 (+3672.73%)
Mutual labels:  authentication, authorization
Buji Pac4j
pac4j security library for Shiro: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 444 (+1918.18%)
Mutual labels:  authentication, authorization

NAME Dancer::Plugin::Auth::Extensible - extensible authentication framework for Dancer apps

DESCRIPTION A user authentication and authorisation framework plugin for Dancer apps.

Makes it easy to require a user to be logged in to access certain
routes, provides role-based access control, and supports various
authentication methods/sources (config file, database, Unix system
users, etc).

Designed to support multiple authentication realms and to be as
extensible as possible, and to make secure password handling easy. The
base class for auth providers makes handling `RFC2307'-style hashed
passwords really simple, so you have no excuse for storing plain-text
passwords. A simple script to generate RFC2307-style hashed passwords is
included (it now defaults to SHA-512), or you can use Crypt::SaltedHash
yourself to do so (but choose a secure algorhytm), or use the
`slappasswd' utility if you have it installed.

SYNOPSIS Configure the plugin to use the authentication provider class you wish to use:

  plugins:
        Auth::Extensible:
            realms:
                users:
                    provider: Example
                    ....

The configuration you provide will depend on the authentication provider
module in use. For a simple example, see
Dancer::Plugin::Auth::Extensible::Provider::Config.

Define that a user must be logged in and have the proper permissions to
access a route:

    get '/secret' => require_role Confidant => sub { tell_secrets(); };

Define that a user must be logged in to access a route - and find out
who is logged in with the `logged_in_user' keyword:

    get '/users' => require_login sub {
        my $user = logged_in_user;
        return "Hi there, $user->{username}";
    };

AUTHENTICATION PROVIDERS For flexibility, this authentication framework uses simple authentication provider classes, which implement a simple interface and do whatever is required to authenticate a user against the chosen source of authentication.

For an example of how simple provider classes are, so you can build your
own if required or just try out this authentication framework plugin
easily, see Dancer::Plugin::Auth::Extensible::Provider::Example.

This framework supplies the following providers out-of-the-box:

Dancer::Plugin::Auth::Extensible::Provider::Unix
    Authenticates users using system accounts on Linux/Unix type boxes

Dancer::Plugin::Auth::Extensible::Provider::Database
    Authenticates users stored in a database table

Dancer::Plugin::Auth::Extensible::Provider::Config
    Authenticates users stored in the app's config

Need to write your own? Just subclass
Dancer::Plugin::Auth::Extensible::Provider::Base and implement the
required methods, and you're good to go!

CONTROLLING ACCESS TO ROUTES Keywords are provided to check if a user is logged in / has appropriate roles.

require_login - require the user to be logged in
        get '/dashboard' => require_login sub { .... };

    If the user is not logged in, they will be redirected to the login
    page URL to log in. The default URL is `/login' - this may be
    changed with the `login_page' option.

require_role - require the user to have a specified role
        get '/beer' => require_role BeerDrinker => sub { ... };

    Requires that the user be logged in as a user who has the specified
    role. If the user is not logged in, they will be redirected to the
    login page URL. If they are logged in, but do not have the required
    role, they will be redirected to the access denied URL.

require_any_roles - require the user to have one of a list of roles
        get '/drink' => require_any_role [qw(BeerDrinker VodaDrinker)] => sub {
            ...
        };

    Requires that the user be logged in as a user who has any one (or
    more) of the roles listed. If the user is not logged in, they will
    be redirected to the login page URL. If they are logged in, but do
    not have any of the specified roles, they will be redirected to the
    access denied URL.

require_all_roles - require the user to have all roles listed
        get '/foo' => require_all_roles [qw(Foo Bar)] => sub { ... };

    Requires that the user be logged in as a user who has all of the
    roles listed. If the user is not logged in, they will be redirected
    to the login page URL. If they are logged in but do not have all of
    the specified roles, they will be redirected to the access denied
    URL.

Replacing the Default /login ' and /login/denied ' Routes By default, the plugin adds a route to present a simple login form at that URL. If you would rather add your own, set the no_default_pages' setting to a true value, and define your own route which responds to/login' with a login page. Alternatively you can let DPAE add the routes and handle the status codes, etc. and simply define the setting login_page_handler' and/orpermission_denied_page_handler' with the name of a subroutine to be called to handle the route. Note that it must be a fully qualified sub. E.g.

    plugins:
      Auth::Extensible:
        login_page_handler: 'My::App:login_page_handler'
        permission_denied_page_handler: 'My::App:permission_denied_page_handler'

Then in your code you might simply use a template:

    sub permission_denied_page_handler {
        template 'account/login';
    }

If the user is logged in, but tries to access a route which requires a
specific role they don't have, they will be redirected to the
"permission denied" page URL, which defaults to `/login/denied' but may
be changed using the `denied_page' option.

Again, by default a route is added to respond to that URL with a default
page; again, you can disable this by setting `no_default_pages' and
creating your own.

This would still leave the routes `post '/login'' and `any '/logout''
routes in place. To disable them too, set the option `no_login_handler'
to a true value. In this case, these routes should be defined by the
user, and should do at least the following:

    post '/login' => sub {
        my ($success, $realm) = authenticate_user(
            params->{username}, params->{password}
        );
        if ($success) {
            session logged_in_user => params->{username};
            session logged_in_user_realm => $realm;
            # other code here
        } else {
            # authentication failed
        }
    };

    any '/logout' => sub {
        session->destroy;
    };

If you want to use the default `post '/login'' and `any '/logout''
routes you can configure them. See below.

Keywords require_login Used to wrap a route which requires a user to be logged in order to access it.

        get '/secret' => require_login sub { .... };

require_role
    Used to wrap a route which requires a user to be logged in as a user
    with the specified role in order to access it.

        get '/beer' => require_role BeerDrinker => sub { ... };

    You can also provide a regular expression, if you need to match the
    role using a regex - for example:

        get '/beer' => require_role qr/Drinker$/ => sub { ... };

require_any_role
    Used to wrap a route which requires a user to be logged in as a user
    with any one (or more) of the specified roles in order to access it.

        get '/foo' => require_any_role [qw(Foo Bar)] => sub { ... };

require_all_roles
    Used to wrap a route which requires a user to be logged in as a user
    with all of the roles listed in order to access it.

        get '/foo' => require_all_roles [qw(Foo Bar)] => sub { ... };

logged_in_user
    Returns a hashref of details of the currently logged-in user, if
    there is one.

    The details you get back will depend upon the authentication
    provider in use.

user_has_role
    Check if a user has the role named.

    By default, the currently-logged-in user will be checked, so you
    need only name the role you're looking for:

        if (user_has_role('BeerDrinker')) { pour_beer(); }

    You can also provide the username to check;

        if (user_has_role($user, $role)) { .... }

user_roles
    Returns a list of the roles of a user.

    By default, roles for the currently-logged-in user will be checked;
    alternatively, you may supply a username to check.

    Returns a list or arrayref depending on context.

authenticate_user
    Usually you'll want to let the built-in login handling code deal
    with authenticating users, but in case you need to do it yourself,
    this keyword accepts a username and password, and optionally a
    specific realm, and checks whether the username and password are
    valid.

    For example:

        if (authenticate_user($username, $password)) {
            ...
        }

    If you are using multiple authentication realms, by default each
    realm will be consulted in turn. If you only wish to check one of
    them (for instance, you're authenticating an admin user, and there's
    only one realm which applies to them), you can supply the realm as
    an optional third parameter.

    In boolean context, returns simply true or false; in list context,
    returns `($success, $realm)'.

SAMPLE CONFIGURATION In your application's configuration file:

    session: simple
    plugins:
        Auth::Extensible:
            # Set to 1 if you want to disable the use of roles (0 is default)
            disable_roles: 0
            # After /login: If no return_url is given: land here ('/' is default)
            user_home_page: '/user'
            # After /logout: If no return_url is given: land here (no default)
            exit_page: '/'
        
            # List each authentication realm, with the provider to use and the
            # provider-specific settings (see the documentation for the provider
            # you wish to use)
            realms:
                realm_one:
                    provider: Database
                        db_connection_name: 'foo'

Please note that you must have a session provider configured. The
authentication framework requires sessions in order to track information
about the currently logged in user. Please see Dancer::Session for
information on how to configure session management within your
application.

AUTHOR David Precious, `'

BUGS / FEATURE REQUESTS This is an early version; there may still be bugs present or features missing.

This is developed on GitHub - please feel free to raise issues or pull
requests against the repo at:
https://github.com/bigpresh/Dancer-Plugin-Auth-Extensible

ACKNOWLEDGEMENTS Valuable feedback on the early design of this module came from many people, including Matt S Trout (mst), David Golden (xdg), Damien Krotkine (dams), Daniel Perrett, and others.

Configurable login/logout URLs added by Rene (hertell)

Regex support for require_role by chenryn

Support for user_roles looking in other realms by Colin Ewen (casao)

Config options for default login/logout handlers by Henk van Oers
(hvoers)

LICENSE AND COPYRIGHT Copyright 2012-16 David Precious.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].