line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
77
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Mojolicious::Plugin::MozPersona::Controller; |
5
|
|
|
|
|
|
|
$Mojolicious::Plugin::MozPersona::Controller::VERSION = '0.05'; |
6
|
|
|
|
|
|
|
# ABSTRACT: Default implementation for server side functions for "Persona" authentication. |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Mojo::Base 'Mojolicious::Controller'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
851930
|
use Mojo::JSON qw(decode_json); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
96
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
813
|
use Mozilla::CA qw(); |
|
1
|
|
|
|
|
271
|
|
|
1
|
|
|
|
|
26
|
|
13
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
816
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub signin { |
17
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
$ENV{'MOJO_CA_FILE'} = Mozilla::CA::SSL_ca_file(); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
my $persona_response = ''; |
22
|
0
|
|
|
|
|
|
my $result = ''; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
eval { |
25
|
0
|
|
|
|
|
|
$persona_response = $self->ua->post( |
26
|
|
|
|
|
|
|
$self->stash('_persona_service') |
27
|
|
|
|
|
|
|
=> form => { |
28
|
|
|
|
|
|
|
assertion => $self->param('assertion'), |
29
|
|
|
|
|
|
|
audience => $self->stash('_persona_audience'), |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
)->res; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
$result = decode_json $persona_response->body; |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
0
|
|
|
|
if ($@) { |
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->app->log->error("Error verifying assertion with IdP: $@"); |
38
|
0
|
|
|
|
|
|
$self->render( json => { signin => Mojo::JSON->false } ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif ( ! ( $result->{'status'} eq "okay" or $result->{'status'} eq "failure" ) ) { |
41
|
0
|
|
|
|
|
|
require Data::Dumper; |
42
|
0
|
|
|
|
|
|
$self->app->log->error("Invalid response from IdP: " . Data::Dumper::Dumper($result)); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
0
|
0
|
|
|
|
|
if ( $self->app->log->is_debug ) { |
46
|
0
|
|
|
|
|
|
require Data::Dumper; |
47
|
0
|
|
|
|
|
|
$self->app->log->debug("Successfully verified user assertion with IdP: " . Data::Dumper::Dumper($result)); |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
$self->session->{_persona} = $result; |
50
|
0
|
|
|
|
|
|
$self->render( json => { signin => Mojo::JSON->true, result => $result } ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub signout { |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
delete $self->session->{_persona}; |
58
|
0
|
|
|
|
|
|
$self->render( json => { signout => Mojo::JSON->true } ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub js { |
63
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
my %c = %{ $self->stash('_persona_conf') }; |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
foreach my $k ( keys %c ) { |
67
|
0
|
|
|
|
|
|
$self->stash( $k => $c{$k} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# set empty value for optional config |
71
|
0
|
|
|
|
|
|
foreach my $w ( qw( siteLogo privacyPolicy termsOfService returnTo oncancel ) ) { |
72
|
0
|
0
|
|
|
|
|
$self->stash( $w => '' ) unless $c{$w}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->res->headers->content_type('text/javascript'); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my ( $tName, $tFormat, $tHandler ) = split( /\./, $c{'localJsTpl'} ); |
78
|
0
|
0
|
0
|
|
|
|
$tName = 'persona_local_js' unless defined($tName) and $tName; |
79
|
0
|
0
|
0
|
|
|
|
$tFormat = 'txt' unless defined($tFormat) and $tFormat; |
80
|
0
|
0
|
0
|
|
|
|
$tHandler = 'ep' unless defined($tHandler) and $tHandler; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
$self->render( $tName, format => $tFormat, handler => $tHandler ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |