| 1 | 4 | ▶ | use strictures 1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 2 | package Mojito::Auth::Role; | ||
| 3 | 4 | $Mojito::Auth::Role::VERSION = '0.25'; | |
| 4 | 4 | ▶ | use Moo::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 4 | ▶ | use Digest::MD5; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 4 | ▶ | use MooX::Types::MooseLike::Base qw(:all); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 4 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 4 | ▶ | use Data::Dumper::Concise; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | 4 | requires 'get_user', 'add_user', 'remove_user'; | |
| 11 | |||
| 12 | =head1 Name | ||
| 13 | |||
| 14 | Mojito::Auth::Deep - common auth parts | ||
| 15 | |||
| 16 | =head1 Methods | ||
| 17 | |||
| 18 | =head2 add_user | ||
| 19 | |||
| 20 | Provide the username, realm (default Mojito) and password. | ||
| 21 | |||
| 22 | |||
| 23 | =head1 Attributes | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | 4 | has 'first_name' => ( | |
| 28 | is => 'ro', | ||
| 29 | isa => Value, | ||
| 30 | ); | ||
| 31 | 4 | has 'last_name' => ( | |
| 32 | is => 'ro', | ||
| 33 | isa => Value, | ||
| 34 | ); | ||
| 35 | 4 | has 'email' => ( | |
| 36 | is => 'ro', | ||
| 37 | isa => Value, | ||
| 38 | ); | ||
| 39 | 4 | has 'username' => ( | |
| 40 | is => 'ro', | ||
| 41 | isa => Value, | ||
| 42 | ); | ||
| 43 | 4 | has 'realm' => ( | |
| 44 | is => 'ro', | ||
| 45 | isa => Value, | ||
| 46 | ); | ||
| 47 | 4 | has 'password' => ( | |
| 48 | is => 'ro', | ||
| 49 | isa => Value, | ||
| 50 | ); | ||
| 51 | 4 | has 'env' => ( | |
| 52 | is => 'ro', | ||
| 53 | isa => Value, | ||
| 54 | ); | ||
| 55 | 4 | has 'digest_authen_cb' => ( | |
| 56 | is => 'ro', | ||
| 57 | isa => CodeRef, | ||
| 58 | lazy => 1, | ||
| 59 | builder => '_build_digest_authen_cb', | ||
| 60 | ); | ||
| 61 | |||
| 62 | =head1 Methods | ||
| 63 | |||
| 64 | =head2 authen_cb | ||
| 65 | |||
| 66 | The authentication callback used by Plack::Middleware::Authen::Basic. | ||
| 67 | |||
| 68 | =cut | ||
| 69 | |||
| 70 | 0 | ▶ | sub authen_cb { |
|
Subroutine
authen_cb: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 71 | 0 | my ( $username, $password ) = @_; | |
| 72 | 0 | return $password eq get_password_for($username); | |
| 73 | } | ||
| 74 | |||
| 75 | =head2 _build_digest_authen_cb | ||
| 76 | |||
| 77 | The authentication callback used by Plack::Middleware::Authen::Digest. | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 0 | ▶ | sub _build_digest_authen_cb { |
|
Subroutine
_build_digest_authen_cb: not called CC=1 SCAR=6.9
| |||
| 82 | 0 | my ($self) = @_; | |
| 83 | 0 | ▶ | my $coderef = sub { |
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||
| 84 | 0 | my $username = shift; | |
| 85 | 0 | return $self->get_HA1_for($username); | |
| 86 | 0 | }; | |
| 87 | 0 | return $coderef; | |
| 88 | } | ||
| 89 | |||
| 90 | =head2 get_password_for | ||
| 91 | |||
| 92 | Given a username, return their password. | ||
| 93 | |||
| 94 | =cut | ||
| 95 | |||
| 96 | 0 | ▶ | sub get_password_for { |
|
Subroutine
get_password_for: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 97 | 0 | my ( $self, $username ) = @_; | |
| 98 | 0 | my $user = $self->get_user($username); | |
| 99 | 0 | return $user->{password}; | |
| 100 | } | ||
| 101 | |||
| 102 | =head2 get_HA1_for | ||
| 103 | |||
| 104 | Given a username, return their HA1 := md5_hex("$username:$realm:$password") | ||
| 105 | |||
| 106 | =cut | ||
| 107 | |||
| 108 | 0 | ▶ | sub get_HA1_for { |
|
Subroutine
get_HA1_for: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 109 | 0 | my ( $self, $username ) = @_; | |
| 110 | 0 | my $user = $self->get_user($username); | |
| 111 | 0 | return $user->{HA1}; | |
| 112 | } | ||
| 113 | |||
| 114 | =head2 secret | ||
| 115 | |||
| 116 | Used by Plack::Middleware::Auth::Digest | ||
| 117 | |||
| 118 | =cut | ||
| 119 | |||
| 120 | sub _secret () { ## no critic | ||
| 121 | 'més_vi_si_us_plau'; | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | 4 | 1 | |