Extensible/Provider/Example.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 36 SCAR 6.9
CC
1
Cov
0%
users
2.0
authenticate_user
2.0
get_user_details
2.0
CRAP 2.0
1 package Dancer::Plugin::Auth::Extensible::Provider::Example;
2  
3 use strict;
4 use warnings;
5  
6 use base "Dancer::Plugin::Auth::Extensible::Provider::Base";
7  
8 # A more sensible provider would be likely to get this information from e.g. a
9 # database (or LDAP, or...) rather than hardcoding it. This, however, is an
10 # example.
11 sub users {
12 return {
13 'dave' => {
14 name => 'David Precious',
15 password => 'beer',
16 roles => [ qw(Motorcyclist BeerDrinker) ],
17 },
18 'bob' => {
19 name => 'Bob The Builder',
20 password => 'canhefixit',
21 roles => [ qw(Fixer) ],
22 },
23 };
24 }
25  
26 =head1 NAME
27  
28 Dancer::Plugin::Auth::Extensible::Example - example authentication provider
29  
30  
31 =head1 DESCRIPTION
32  
33 This class is intended as an example of what an authentication provider class
34 should do. It is not intended for serious use (clearly).
35  
36 See L<Dancer::Plugin::Auth::Extensible> for details on how to use the
37 authentication framework, including how to pick a more useful authentication
38 provider.
39  
40 However, if you just want to test the framework, or want an example to work from
41 to build your own authentication provider class, this may be of use.
42  
43 =cut
44  
45 =head1 Class methods
46  
47 =over
48  
49 =item authenticate_user
50  
51 Given the username and password entered by the user, return true if they are
52 authenticated, or false if not.
53  
54 =cut
55  
56 sub authenticate_user {
57 my ($self, $username, $password) = @_;
58 my $user_details = $self->get_user_details($username) or return;
59 return $self->match_password($password, $user_details->{password});
60 }
61  
62 =item get_user_details
63  
64 Given a username, return details about the user. The details returned will vary
65 depending on the provider; some providers may be able to return various data
66 about the user, some may not, depending on the authentication source.
67  
68 Details should be returned as a hashref.
69  
70 =cut
71  
72 sub get_user_details {
73 my ($self, $username) = @_;
74  
75 return $self->users->{lc $username};
76 }
77  
78 =item get_user_roles
79  
80 Given a username, return a list of roles that user has.
81  
82 =back
83  
84 =cut
85  
86 sub get_user_roles {
87 my ($self, $username) = @_;
88  
89 my $user_details = $self->get_user_details($username) or return;
90 return $user_details->{roles};
91 }
92  
93  
94  
95 1;
96