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