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