line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DigestAuth; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
37747
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
181
|
|
4
|
6
|
|
|
6
|
|
22
|
use warnings; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
158
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
21
|
use Carp 'croak'; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
297
|
|
7
|
6
|
|
|
6
|
|
24
|
use Scalar::Util 'blessed'; |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
218
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
21
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
38
|
|
10
|
6
|
|
|
6
|
|
2772
|
use Mojolicious::Plugin::DigestAuth::DB; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
115
|
|
11
|
6
|
|
|
6
|
|
2007
|
use Mojolicious::Plugin::DigestAuth::RequestHandler; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
1818
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub register |
16
|
|
|
|
|
|
|
{ |
17
|
68
|
|
|
68
|
1
|
2380964
|
my ($self, $app, $user_defaults) = @_; |
18
|
|
|
|
|
|
|
|
19
|
68
|
|
|
|
|
322
|
my %defaults = %$user_defaults; |
20
|
68
|
|
100
|
|
|
475
|
$defaults{realm} ||= 'WWW'; |
21
|
68
|
|
100
|
|
|
306
|
$defaults{expires} ||= 300; |
22
|
68
|
50
|
33
|
|
|
585
|
$defaults{secret} ||= $app->can('secret') ? $app->secret : $app->secrets; # >= 4.91 has no secret() |
23
|
68
|
50
|
|
|
|
718
|
$defaults{secret} = $defaults{secret}->[0] if ref($defaults{secret}) eq 'ARRAY'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->helper(digest_auth => sub { |
26
|
71
|
|
|
71
|
|
41813
|
my $c = shift; |
27
|
|
|
|
|
|
|
|
28
|
71
|
|
|
|
|
78
|
my $route; |
29
|
71
|
100
|
|
|
|
197
|
$route = shift if @_ % 2; |
30
|
|
|
|
|
|
|
|
31
|
71
|
|
|
|
|
256
|
my $options = { %defaults, @_ }; |
32
|
71
|
100
|
|
|
|
370
|
croak 'you must setup an authentication source via the "allow" option' if !defined $options->{allow}; |
33
|
|
|
|
|
|
|
|
34
|
70
|
|
|
|
|
97
|
my $allow = delete $options->{allow}; |
35
|
70
|
50
|
33
|
|
|
341
|
if(blessed($allow) && $allow->can('get')) { |
|
|
50
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$options->{password_db} = $allow; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif(ref($allow) eq 'HASH') { |
39
|
|
|
|
|
|
|
# Normalize simple config, otherwise we assume a hash of: realm => { user => 'password' ... } |
40
|
70
|
50
|
|
|
|
224
|
if(ref((values %$allow)[0]) ne 'HASH') { |
41
|
70
|
|
|
|
|
254
|
$allow = { $options->{realm} => { %$allow } }; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
70
|
|
|
|
|
480
|
$options->{password_db} = Mojolicious::Plugin::DigestAuth::DB::Hash->new($allow); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
|
|
|
|
|
|
# Assume it's a file |
48
|
0
|
|
|
|
|
0
|
$options->{password_db} = Mojolicious::Plugin::DigestAuth::DB::File->new($allow); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
70
|
|
|
|
|
377
|
my $handler = Mojolicious::Plugin::DigestAuth::RequestHandler->new($options); |
52
|
67
|
100
|
|
|
|
124
|
if($route) { |
53
|
1
|
50
|
|
|
|
4
|
my $r = $c->app->routes->can('bridge') ? |
54
|
|
|
|
|
|
|
$c->app->routes->bridge($route) : |
55
|
|
|
|
|
|
|
$c->app->routes->under($route); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return $r->to(cb => sub { |
58
|
2
|
|
|
|
|
11608
|
$handler->authenticate(shift); |
59
|
1
|
|
|
|
|
215
|
}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
66
|
|
|
|
|
203
|
$handler->authenticate($c); |
63
|
68
|
|
|
|
|
581
|
}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |