line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::DigestAuth; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
80981
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
214
|
|
4
|
6
|
|
|
6
|
|
36
|
use warnings; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
214
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
33
|
use Carp 'croak'; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
442
|
|
7
|
6
|
|
|
6
|
|
54
|
use Scalar::Util 'blessed'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
362
|
|
8
|
|
|
|
|
|
|
|
9
|
6
|
|
|
6
|
|
52
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
46
|
|
10
|
6
|
|
|
6
|
|
4394
|
use Mojolicious::Plugin::DigestAuth::DB; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
193
|
|
11
|
6
|
|
|
6
|
|
3477
|
use Mojolicious::Plugin::DigestAuth::RequestHandler; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
3377
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub register |
16
|
|
|
|
|
|
|
{ |
17
|
68
|
|
|
68
|
1
|
2495445
|
my ($self, $app, $user_defaults) = @_; |
18
|
|
|
|
|
|
|
|
19
|
68
|
|
|
|
|
333
|
my %defaults = %$user_defaults; |
20
|
68
|
|
100
|
|
|
545
|
$defaults{realm} ||= 'WWW'; |
21
|
68
|
|
100
|
|
|
356
|
$defaults{expires} ||= 300; |
22
|
68
|
50
|
33
|
|
|
555
|
$defaults{secret} ||= $app->can('secret') ? $app->secret : $app->secrets; # >= 4.91 has no secret() |
23
|
68
|
50
|
|
|
|
1741
|
$defaults{secret} = $defaults{secret}->[0] if ref($defaults{secret}) eq 'ARRAY'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$app->helper(digest_auth => sub { |
26
|
71
|
|
|
71
|
|
57427
|
my $c = shift; |
27
|
|
|
|
|
|
|
|
28
|
71
|
|
|
|
|
133
|
my $route; |
29
|
71
|
100
|
|
|
|
282
|
$route = shift if @_ % 2; |
30
|
|
|
|
|
|
|
|
31
|
71
|
|
|
|
|
361
|
my $options = { %defaults, @_ }; |
32
|
71
|
100
|
|
|
|
494
|
croak 'you must setup an authentication source via the "allow" option' if !defined $options->{allow}; |
33
|
|
|
|
|
|
|
|
34
|
70
|
|
|
|
|
165
|
my $allow = delete $options->{allow}; |
35
|
70
|
50
|
33
|
|
|
460
|
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
|
|
|
|
287
|
if(ref((values %$allow)[0]) ne 'HASH') { |
41
|
70
|
|
|
|
|
309
|
$allow = { $options->{realm} => { %$allow } }; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
70
|
|
|
|
|
386
|
$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
|
|
|
|
|
342
|
my $handler = Mojolicious::Plugin::DigestAuth::RequestHandler->new($options); |
52
|
67
|
100
|
|
|
|
253
|
if($route) { |
53
|
1
|
50
|
|
|
|
6
|
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
|
|
|
|
|
25874
|
$handler->authenticate(shift); |
59
|
1
|
|
|
|
|
532
|
}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
66
|
|
|
|
|
252
|
$handler->authenticate($c); |
63
|
68
|
|
|
|
|
601
|
}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |