| 1 | package Articulate::Authentication; | ||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | with 'Articulate::Role::Component'; | |||||||||
| 7 | 5 | ▶ | 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 | 4 | ▶ | coerce => sub { instantiate_array(@_) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 5 | ); | |||||||||
| 39 | |||||||||||
| 40 | =head3 login | ||||||||||
| 41 | |||||||||||
| 42 | $authentication->login($credentials); | ||||||||||
| 43 | $authentication->login( $user_id, $password ); | ||||||||||
| 44 | |||||||||||
| 45 | 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). | ||||||||||
| 46 | |||||||||||
| 47 | 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). | ||||||||||
| 48 | |||||||||||
| 49 | =cut | ||||||||||
| 50 | |||||||||||
| 51 | sub login { | ||||||||||
| 52 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
login: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 53 | 0 | my $credentials = credentials @_; | |||||||||
| 54 | 0 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 55 | 0 | ▶ | return $credentials if $provider->authenticate($credentials); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 0 | ▶ | return $credentials if $credentials->rejected; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | } | ||||||||||
| 58 | 0 | return $credentials->deny('No provider authenticated these credentials'); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | =head3 create_user | ||||||||||
| 62 | |||||||||||
| 63 | $authentication->create_user( $user_id, $password ); | ||||||||||
| 64 | |||||||||||
| 65 | Requests that a new user is created. Each provider must respond true, false, or undef. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | sub create_user { | ||||||||||
| 70 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
create_user: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 71 | 0 | my $user_id = shift; | |||||||||
| 72 | 0 | my $password = shift; | |||||||||
| 73 | 0 | foreach my $provider ( @{ $self->providers } ) { | |||||||||
| 74 | 0 | ▶ | if ( defined( $provider->create_user( $user_id, $password ) ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | 0 | return ($user_id); | |||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | 0 | return (undef); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | =head1 SEE ALSO | ||||||||||
| 82 | |||||||||||
| 83 | =over | ||||||||||
| 84 | |||||||||||
| 85 | =item * L<Articulate::Authorisation> | ||||||||||
| 86 | |||||||||||
| 87 | =item * L<Articulate::Credentials> | ||||||||||
| 88 | |||||||||||
| 89 | =back | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 5 | 1; | |||||||||