| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Mojolicious::Plugin::MozPersona; |
|
3
|
|
|
|
|
|
|
{ |
|
4
|
|
|
|
|
|
|
$Mojolicious::Plugin::MozPersona::VERSION = '0.01_01'; |
|
5
|
|
|
|
|
|
|
} |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Minimalistic integration of Mozillas "Persona" authentication system in Mojolicious apps |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
17948
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
10
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
264
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use File::Basename 'dirname'; |
|
16
|
|
|
|
|
|
|
use File::Spec::Functions 'catdir'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use Mojolicious::Plugin::MozPersona::Controller; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %defaults = ( |
|
22
|
|
|
|
|
|
|
audience => '', |
|
23
|
|
|
|
|
|
|
siteName => '', |
|
24
|
|
|
|
|
|
|
service => 'https://verifier.login.persona.org/verify', |
|
25
|
|
|
|
|
|
|
namespace => 'Mojolicious::Plugin::MozPersona::Controller', |
|
26
|
|
|
|
|
|
|
signinId => 'personaSignin', |
|
27
|
|
|
|
|
|
|
signinPath => '/_persona/signin', |
|
28
|
|
|
|
|
|
|
signoutId => 'personaSignout', |
|
29
|
|
|
|
|
|
|
signoutPath => '/_persona/signout', |
|
30
|
|
|
|
|
|
|
autoHook => { css => 0, jquery => 1, persona => 1, local => 1, uid => 1 }, |
|
31
|
|
|
|
|
|
|
localJsPath => '/_persona/localjs', |
|
32
|
|
|
|
|
|
|
localJsTpl => '_persona/local_js.txt.ep', |
|
33
|
|
|
|
|
|
|
personaJsPath => 'https://login.persona.org/include.js', |
|
34
|
|
|
|
|
|
|
); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub register { |
|
38
|
|
|
|
|
|
|
my ( $self, $app ) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $defaultHooks = delete $defaults{'autoHook'}; |
|
41
|
|
|
|
|
|
|
my (%conf) = ( %defaults, %{ $_[2] || {} } ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$conf{'autoHook'} = {} unless exists $conf{'autoHook'}; |
|
44
|
|
|
|
|
|
|
foreach my $h ( keys %{$defaultHooks} ) { |
|
45
|
|
|
|
|
|
|
if ( ref $conf{'autoHook'} && ! exists $conf{'autoHook'}->{$h} ) { |
|
46
|
|
|
|
|
|
|
$conf{'autoHook'}->{$h} = $defaultHooks->{$h}; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$conf{'siteName'} =~ tr/"'//d; |
|
51
|
|
|
|
|
|
|
$conf{'signinPath'} =~ tr/"'//d; |
|
52
|
|
|
|
|
|
|
$conf{'signoutPath'} =~ tr/"'//d; |
|
53
|
|
|
|
|
|
|
$conf{'signinId'} =~ tr/"'#//d; |
|
54
|
|
|
|
|
|
|
$conf{'signoutId'} =~ tr/"'#//d; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
die "Missing required configuration parameter: 'audience'!" unless $conf{'audience'}; |
|
57
|
|
|
|
|
|
|
die "Missing required configuration parameter: 'siteName'!" unless $conf{'siteName'}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Append "templates" and "public" directories |
|
60
|
|
|
|
|
|
|
my $base = catdir( dirname(__FILE__), 'MozPersona' ); |
|
61
|
|
|
|
|
|
|
push @{ $app->renderer->paths }, catdir( $base, 'templates' ); |
|
62
|
|
|
|
|
|
|
push @{ $app->static->paths }, catdir( $base, 'public' ); |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
push @{ $app->renderer->classes }, __PACKAGE__; |
|
65
|
|
|
|
|
|
|
push @{ $app->static->classes }, __PACKAGE__; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$app->routes->route( $conf{signinPath} )->via('POST')->to( |
|
68
|
|
|
|
|
|
|
namespace => $conf{namespace}, |
|
69
|
|
|
|
|
|
|
action => 'signin', |
|
70
|
|
|
|
|
|
|
_persona_audience => $conf{audience}, |
|
71
|
|
|
|
|
|
|
_persona_service => $conf{service}, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
$app->routes->route( $conf{signoutPath} )->via('POST')->to( |
|
74
|
|
|
|
|
|
|
namespace => $conf{namespace}, |
|
75
|
|
|
|
|
|
|
action => 'signout', |
|
76
|
|
|
|
|
|
|
_persona_audience => $conf{audience}, |
|
77
|
|
|
|
|
|
|
_persona_service => $conf{service}, |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
$app->routes->route( $conf{localJsPath} )->via('GET')->to( |
|
80
|
|
|
|
|
|
|
namespace => $conf{namespace}, |
|
81
|
|
|
|
|
|
|
action => 'js', |
|
82
|
|
|
|
|
|
|
_persona_conf => \%conf, |
|
83
|
|
|
|
|
|
|
); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if ( $conf{'autoHook'} ) { |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $head_block = ''; |
|
88
|
|
|
|
|
|
|
if ( $conf{'autoHook'}->{'css'} ) { |
|
89
|
|
|
|
|
|
|
$head_block .= ''; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
if ( $conf{'autoHook'}->{'jquery'} ) { |
|
92
|
|
|
|
|
|
|
$head_block .= ''; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $end_block = ''; |
|
96
|
|
|
|
|
|
|
if ( $conf{'autoHook'}->{'persona'} ) { |
|
97
|
|
|
|
|
|
|
$end_block .= qq||; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
if ( $conf{'autoHook'}->{'local'} ) { |
|
100
|
|
|
|
|
|
|
$end_block .= qq||; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$app->hook( |
|
104
|
|
|
|
|
|
|
after_dispatch => sub { |
|
105
|
|
|
|
|
|
|
my ($c) = @_; |
|
106
|
|
|
|
|
|
|
return unless index( $c->res->headers->content_type, 'html' ) >= 0; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $body = $c->res->body; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
if ( $conf{'autoHook'}->{'uid'} ) { |
|
111
|
|
|
|
|
|
|
if ( defined( $c->session('_persona') ) |
|
112
|
|
|
|
|
|
|
&& $c->session('_persona')->{'status'} eq 'okay' |
|
113
|
|
|
|
|
|
|
) |
|
114
|
|
|
|
|
|
|
{ |
|
115
|
|
|
|
|
|
|
my $email = $c->session('_persona')->{'email'}; |
|
116
|
|
|
|
|
|
|
$body |
|
117
|
|
|
|
|
|
|
=~ s!!$head_block!o; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
else { |
|
120
|
|
|
|
|
|
|
$body |
|
121
|
|
|
|
|
|
|
=~ s!!$head_block!o; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
elsif ($head_block) { |
|
125
|
|
|
|
|
|
|
$body =~ s!!$head_block!o; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
if ($end_block) { |
|
129
|
|
|
|
|
|
|
$body =~ s!!$end_block!o; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
$c->res->body($body); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
); |
|
134
|
|
|
|
|
|
|
} ## end if ( $conf{'autoHook'}) |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
return; |
|
137
|
|
|
|
|
|
|
} ## end sub register |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
1; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 NAME |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Mojolicious::Plugin::MozPersona - Minimalistic integration of Mozillas "Persona" authentication system in Mojolicious apps |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 VERSION |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
version 0.01_01 |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Mojolicious::Lite |
|
157
|
|
|
|
|
|
|
plugin 'MozPersona' => { |
|
158
|
|
|
|
|
|
|
audience => 'http://127.0.0.1:3000/', |
|
159
|
|
|
|
|
|
|
siteName => 'My spectacular new site!', |
|
160
|
|
|
|
|
|
|
autoHook => { css => 1 }, |
|
161
|
|
|
|
|
|
|
}; |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Mojolicious |
|
164
|
|
|
|
|
|
|
# $self->plugin( moz_persona => { |
|
165
|
|
|
|
|
|
|
# audience => 'https://example.org:8443/', |
|
166
|
|
|
|
|
|
|
# siteName => 'My shiny new site!' |
|
167
|
|
|
|
|
|
|
# }); |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
get '/' => sub { |
|
170
|
|
|
|
|
|
|
my $self = shift; |
|
171
|
|
|
|
|
|
|
$self->render('index'); |
|
172
|
|
|
|
|
|
|
}; |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
app->start; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__DATA__ |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
@@ index.html.ep |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Mozilla Persona Test |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
% if ( defined(session '_persona') && (session '_persona')->{'status'} eq 'okay' ) { |
|
184
|
|
|
|
|
|
|
% my $email = (session '_persona')->{'email'}; |
|
185
|
|
|
|
|
|
|
<%= $email %> abmelden |
|
186
|
|
|
|
|
|
|
% } else { |
|
187
|
|
|
|
|
|
|
Anmelden mit Ihrer Email |
|
188
|
|
|
|
|
|
|
% } |
|
189
|
|
|
|
|
|
|
Some dummy content. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
:confirm b6 |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L is a L plugin. |
|
196
|
|
|
|
|
|
|
It provides a minimalistic integration of Mozillas "Persona" authentication |
|
197
|
|
|
|
|
|
|
system in Mojolicious apps. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This modules adds a few routes (at C, C and C, |
|
200
|
|
|
|
|
|
|
see below) to your app which refer to the code that is responsible for handling |
|
201
|
|
|
|
|
|
|
the local, application-specific server side part of the B authentication model. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
It also by default registers a C hook that automatically inserts |
|
204
|
|
|
|
|
|
|
some C |