Articulate/Authentication.pm

filter: Statementstmt 50.0% 16 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 2 / 2 totaltotal 47.9% 23 / 48 SCAR 25.6
CC
6
Cov
42%
login
20.0
create_user
12.0
__ANON__
2.0
CRAP 13.0
« Articulate/Augmentation/Interpreter.pm ↑ Summary Articulate/Service/SimplePreviews.pm »
1 package Articulate::Authentication;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 with 'Articulate::Role::Component';
7 4 ▶use Articulate::Syntax qw(credentials instantiate_array);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Articulate::Authentication - determine if a user who they claim to be
12  
13 =head1 SYNOPSIS
14  
15 # in config:
16 components:
17 authentication:
18 Articulate::Authentication:
19 providers:
20 - Articulate::Authentication::AlwaysAllow
21  
22 # then any component can dp
23 $component->authentication->login($credentials);
24 $component->authentication->login($user_id, $password);
25  
26 =head1 ATTRIBUTE
27  
28 =head3 providers
29  
30 A list of providers which can respond to C<login>.
31  
32 =cut
33  
34 has providers =>
35 is => 'rw',
36 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 3 ▶ coerce => sub { instantiate_array(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 =head3 login
40  
41 $authentication->login($credentials);
42 $authentication->login( $user_id, $password );
43  
44 Asks each provider if the credentials supplied match a known user. Credentials may be in whatever form will satisfy the C<credentials> function in L<Articulate::Credentials> (username and password, hashref or credentials object).
45  
46 Each provider must respond true, false, or undef. A true value means the user is authenticated. A false value means that the user exists but is explicitly refused access (this should only be used in exceptional circumstances) and an undef value means the user cannot be authenticated by the provider (but could be authenticated by some other provider).
47  
48 =cut
49  
50 sub login {
51 0 ▶ my $self = shift;
Subroutine login: not called CC=4 SCAR=30.0
Pod documented
52 0 my $credentials = credentials @_;
53 0 foreach my $provider ( @{ $self->providers } ) {
54 0 ▶ return $credentials if $provider->authenticate( $credentials );
Branch: 1 branch
BranchTrueFalseTotal
if $provider->authenticate($credentials) 0 0 0
55 0 ▶ return $credentials if $credentials->rejected;
Branch: 1 branch
BranchTrueFalseTotal
if $credentials->rejected 0 0 0
56 }
57 0 return $credentials->deny('No provider authenticated these credentials');
58 }
59  
60 =head3 create_user
61  
62 $authentication->create_user( $user_id, $password );
63  
64 Requests that a new user is created. Each provider must respond true, false, or undef.
65  
66 =cut
67  
68 sub create_user {
69 0 ▶ my $self = shift;
Subroutine create_user: not called CC=3 SCAR=24.8
Pod documented
70 0 my $user_id = shift;
71 0 my $password = shift;
72 0 foreach my $provider ( @{ $self->providers } ) {
73 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $provider->create_user($user_id, $password)) 0 0 0
74 defined ( $provider->create_user( $user_id, $password ) )
75 ) {
76 0 return ($user_id);
77 }
78 }
79 0 return (undef);
80 }
81  
82 =head1 SEE ALSO
83  
84 =over
85  
86 =item * L<Articulate::Authorisation>
87  
88 =item * L<Articulate::Credentials>
89  
90 =back
91  
92 =cut
93  
94 4 1;
« Articulate/Augmentation/Interpreter.pm ↑ Summary Articulate/Service/SimplePreviews.pm »