| 1 | package Dancer::Plugin::Auth::Extensible::Provider::Config; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use base "Dancer::Plugin::Auth::Extensible::Provider::Base"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Dancer::Plugin::Auth::Extensible::Config - example auth provider using app config | ||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||
| 14 | |||||||||||
| 15 | This is a simple authentication provider which authenticates based on a list of | ||||||||||
| 16 | usernames, passwords (crypted, preferably - see below) and role specifications | ||||||||||
| 17 | provided in the realm definition in your app's config file. | ||||||||||
| 18 | |||||||||||
| 19 | This class is primarily intended as an example of what an authentication | ||||||||||
| 20 | provider class should do; however, if you just want simple user authentication | ||||||||||
| 21 | with user details stored in your app's config file, it may well suit your needs. | ||||||||||
| 22 | |||||||||||
| 23 | See L<Dancer::Plugin::Auth::Extensible> for details on how to use the | ||||||||||
| 24 | authentication framework. | ||||||||||
| 25 | |||||||||||
| 26 | =head1 SYNOPSIS | ||||||||||
| 27 | |||||||||||
| 28 | In your app's C<config.yml>: | ||||||||||
| 29 | |||||||||||
| 30 | plugins: | ||||||||||
| 31 | Auth::Extensible: | ||||||||||
| 32 | realms: | ||||||||||
| 33 | config: | ||||||||||
| 34 | provider: Config | ||||||||||
| 35 | users: | ||||||||||
| 36 | - user: dave | ||||||||||
| 37 | pass: supersecret | ||||||||||
| 38 | roles: | ||||||||||
| 39 | - Developer | ||||||||||
| 40 | - Manager | ||||||||||
| 41 | - BeerDrinker | ||||||||||
| 42 | - user: bob | ||||||||||
| 43 | pass: '{SSHA}+2u1HpOU7ak6iBR6JlpICpAUvSpA/zBM' | ||||||||||
| 44 | roles: | ||||||||||
| 45 | - Tester | ||||||||||
| 46 | |||||||||||
| 47 | As you can see, you can define the usernames, passwords (please use crypted | ||||||||||
| 48 | passwords, RFC2307-style, not plain text (although plain text *is* supported, | ||||||||||
| 49 | but really not a good idea), and the roles for each user (if you're | ||||||||||
| 50 | not planning to use roles, omit the roles section from each user entirely). | ||||||||||
| 51 | |||||||||||
| 52 | =cut | ||||||||||
| 53 | |||||||||||
| 54 | sub authenticate_user { | ||||||||||
| 55 | 8 | ▶ | my ($self, $username, $password) = @_; | ||||||||
|
Subroutine
authenticate_user: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 56 | 8 | ▶ | my $user_details = $self->get_user_details($username) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 4 | return $self->match_password($password, $user_details->{pass}); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # Just return the whole user definition from the config; this way any additional | ||||||||||
| 61 | # fields defined for users will just get passed through. | ||||||||||
| 62 | sub get_user_details { | ||||||||||
| 63 | 35 | ▶ | my ($self, $username) = @_; | ||||||||
|
Subroutine
get_user_details: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | my ($user) = grep { | ||||||||||
| 65 | 70 | $_->{user} eq $username | |||||||||
| 66 | 35 | } @{ $self->realm_settings->{users} }; | |||||||||
| 67 | 35 | return $user; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub get_user_roles { | ||||||||||
| 71 | 9 | ▶ | my ($self, $username) = @_; | ||||||||
|
Subroutine
get_user_roles: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||
| 72 | |||||||||||
| 73 | 9 | ▶ | my $user_details = $self->get_user_details($username) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 9 | return $user_details->{roles}; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 1 | 1; | |||||||||
| 78 | |||||||||||