AuthorizationServer/Defaults.pm

filter: Statementstmt 94.8% 147 / 155 Branchbran 86.1% 62 / 72 Conditioncond 53.3% 24 / 45 MC/DCmcdc 16.0% 4 / 25 Subroutinesub 100% 35 / 35 Podpod 0.0% 0 / 8 totaltotal 80.0% 272 / 340 CC 59 SCAR 20.5
CC
59
Cov
86%
_verify_access_token
15.6
_store_access_token
14.5
_verify_access_token_jwt
12.0
CRAP 7.7
↑ Summary AuthorizationServer/ImplicitGrant.pm »
1 package Net::OAuth2::AuthorizationServer::Defaults;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use Types::Standard qw/ :all /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use Carp qw/ croak /;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Crypt::JWT qw/ encode_jwt decode_jwt /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Crypt::PRNG qw/ random_string /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Time::HiRes qw/ gettimeofday /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use MIME::Base64 qw/ encode_base64 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 10 has 'jwt_secret' => (
17 is => 'ro',
18 isa => Any,
19 required => 0,
20 );
21  
22 has 'jwt_algorithm' => (
23 is => 'ro',
24 isa => Any,
25 required => 0,
26 27 ▶ default => sub { 'HS256' }, # back compat with Mojo::JWT
Subroutine __ANON__: called CC=1 SCAR=0.0
27 10 );
28  
29 has 'jwt_encoding' => (
30 is => 'ro',
31 isa => Str,
32 required => 0,
33 27 ▶ default => sub { 'A128GCM' },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 10 );
35  
36 has 'access_token_ttl' => (
37 is => 'ro',
38 isa => Maybe[Int|CodeRef],
39 required => 0,
40 25 ▶ default => sub { 3600 },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 10 );
42  
43 has [
44 qw/
45 clients
46 access_tokens
47 refresh_tokens
48 /
49 ] => (
50 is => 'ro',
51 isa => Maybe [HashRef],
52 required => 0,
53 61 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
54 10 );
55  
56 10 has [
57 qw/
58 verify_client_cb
59 store_access_token_cb
60 verify_access_token_cb
61 login_resource_owner_cb
62 confirm_by_resource_owner_cb
63 /
64 ] => (
65 is => 'ro',
66 isa => Maybe [CodeRef],
67 required => 0,
68 );
69  
70 25 ▶sub _has_clients { return keys %{ shift->clients // {} } ? 1 : 0 }
Subroutine _has_clients: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
keys %{(shift())->clients // {};} ? : 20 5 25
Condition50%1/2
(shift())->clients // {}
l!l
250
MC/DC0%0/1
(shift())->clients // {}
(shift())->clients
Truth table50%1/2
A
A= (shift())->clients
Aresult
11
00
71 1 ▶sub _uses_auth_codes { die "You must override _uses_auth_codes" };
Subroutine _uses_auth_codes: called CC=1 SCAR=0.0
72  
73 72 ▶sub verify_client {
Subroutine verify_client: called CC=1 SCAR=0.0
Pod undocumented
74 72 _delegate_to_cb_or_private( 'verify_client', @_ );
75 }
76  
77 16 ▶sub store_access_token {
Subroutine store_access_token: called CC=1 SCAR=0.0
Pod undocumented
78 16 _delegate_to_cb_or_private( 'store_access_token', @_ );
79 }
80  
81 102 ▶sub verify_access_token {
Subroutine verify_access_token: called CC=1 SCAR=0.0
Pod undocumented
82 102 _delegate_to_cb_or_private( 'verify_access_token', @_ );
83 }
84  
85 8 ▶sub login_resource_owner {
Subroutine login_resource_owner: called CC=1 SCAR=0.0
Pod undocumented
86 8 _delegate_to_cb_or_private( 'login_resource_owner', @_ );
87 }
88  
89 8 ▶sub confirm_by_resource_owner {
Subroutine confirm_by_resource_owner: called CC=1 SCAR=0.0
Pod undocumented
90 8 _delegate_to_cb_or_private( 'confirm_by_resource_owner', @_ );
91 }
92  
93 37 ▶sub verify_token_and_scope {
Subroutine verify_token_and_scope: called CC=6 SCAR=17.9
Pod undocumented
94 37 my ( $self, %args ) = @_;
95  
96 my ( $refresh_token, $scopes_ref, $auth_header ) =
97 37 @args{ qw/ refresh_token scopes auth_header / };
98  
99 37 my $access_token;
100  
101 37 ▶ if ( !$refresh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $refresh_token) { } 29 8 37
102 29 ▶ if ( $auth_header ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_header) { } 21 8 29
103 21 my ( $auth_type, $auth_access_token ) = split( / /, $auth_header );
104  
105 21 ▶ if ( $auth_type ne 'Bearer' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_type ne 'Bearer') { } 1 20 21
106 1 return ( 0, 'invalid_request' );
107 }
108 else {
109 20 $access_token = $auth_access_token;
110 }
111 }
112 else {
113 8 return ( 0, 'invalid_request' );
114 }
115 }
116 else {
117 8 $access_token = $refresh_token;
118 }
119  
120 # we must have some form of token to continue
121 28 ▶ return ( 0, 'invalid_request' )
Branch: 1 branch
BranchTrueFalseTotal
unless $access_token or $refresh_token 4 24 28
Condition66%2/3
$access_token or $refresh_token
l!l&&r!l&&!r
2404
MC/DC50%1/2
$access_token or $refresh_token
$access_token $refresh_token
Truth table66%2/3
A or B
A= $access_tokenB= $refresh_token
ABresult
1X1
011
000
122 if ( ! $access_token && ! $refresh_token );
123  
124 24 return $self->verify_access_token(
125 %args,
126 access_token => $access_token,
127 scopes => $scopes_ref,
128 is_refresh_token => $refresh_token,
129 );
130 }
131  
132 252 ▶sub _delegate_to_cb_or_private {
Subroutine _delegate_to_cb_or_private: called CC=2 SCAR=6.9
133  
134 252 my $method = shift;
135 252 my $self = shift;
136 252 my %args = @_;
137  
138 252 my $cb_method = "${method}_cb";
139 252 my $p_method = "_$method";
140  
141 252 ▶ if ( my $cb = $self->$cb_method ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $self->$cb_method) { } 116 136 252
142 116 return $cb->( %args );
143 }
144 else {
145 136 return $self->$p_method( %args );
146 }
147 }
148  
149 8 ▶sub _login_resource_owner { 1 }
Subroutine _login_resource_owner: called CC=1 SCAR=0.0
150  
151 8 ▶sub _confirm_by_resource_owner {
Subroutine _confirm_by_resource_owner: called CC=3 SCAR=12.0
152 8 my ( $self,%args ) = @_;
153  
154 # out of the box we just pass back "yes you can" and the list of scopes
155 # note the wantarray is here for backwards compat as this method used
156 # to just return 1 but now passing the scopes back requires an array
157 return wantarray
158 8 ▶ ? ( 1,undef,$args{scopes} // [] )
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 0 8
Condition50%1/2
$args{"scopes"} // []
l!l
80
MC/DC0%0/1
$args{"scopes"} // []
$args{"scopes"}
Truth table50%1/2
A
A= $args{"scopes"}
Aresult
11
00
159 : 1;
160 }
161  
162 16 ▶sub _verify_client {
Subroutine _verify_client: called CC=7 SCAR=19.5
163 16 my ( $self, %args ) = @_;
164  
165 16 my ( $client_id, $scopes_ref ) = @args{ qw/ client_id scopes / };
166  
167 16 ▶ if ( my $client = $self->clients->{ $client_id // '' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $client = $self->clients->{$client_id // ""}) 12 4 16
Condition50%1/2
$client_id // ""
l!l
160
MC/DC0%0/1
$client_id // ""
$client_id
Truth table50%1/2
A
A= $client_id
Aresult
11
00
168 12 my $client_scopes = [];
169  
170 12 ▶ foreach my $scope ( @{ $scopes_ref // [] } ) {
Condition50%1/2
$scopes_ref // []
l!l
120
MC/DC0%0/1
$scopes_ref // []
$scopes_ref
Truth table50%1/2
A
A= $scopes_ref
Aresult
11
00
171 32 ▶ if ( ! exists($self->clients->{ $client_id }{ scopes }{ $scope }) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $self->clients->{$client_id}{'scopes'}{$scope}) { } 4 28 32
elsif ($self->clients->{$client_id}{'scopes'}{$scope}) { } 24 4 28
172 4 return ( 0, 'invalid_scope' );
173 }
174 elsif ( $self->clients->{ $client_id }{ scopes }{ $scope } ) {
175 24 push @{$client_scopes}, $scope;
176 }
177 }
178  
179 8 return ( 1, undef, $client_scopes );
180 }
181  
182 4 return ( 0, 'unauthorized_client' );
183 }
184  
185 16 ▶sub _store_access_token {
Subroutine _store_access_token: called CC=11 SCAR=26.8
186 16 my ( $self, %args ) = @_;
187  
188 my ( $c_id, $auth_code, $access_token, $refresh_token, $expires_in, $scope, $old_refresh_token )
189 = @args{
190 16 qw/ client_id auth_code access_token refresh_token expires_in scopes old_refresh_token / };
191  
192 16 ▶ $expires_in //= $self->get_access_token_ttl(
Condition33%1/3
$expires_in //= $self->get_access_token_ttl("scopes", $scope, "client_id", $c_id)
l!l&&r!l&&!r
0160
MC/DC0%0/2
$expires_in //= $self->get_access_token_ttl("scopes", $scope, "client_id", $c_id)
$expires_in $self->get_access_token_ttl("scopes", $scope, "client_id", $c_id)
Truth table33%1/3
A //= B
A= $expires_inB= $self->get_access_token_ttl("scopes", $scope, "client_id", $c_id)
ABresult
1X1
011
000
193 scopes => $scope,
194 client_id => $c_id,
195 );
196  
197 16 ▶ return 1 if $self->jwt_secret;
Branch: 1 branch
BranchTrueFalseTotal
if $self->jwt_secret 8 8 16
198  
199 8 ▶ if ( !defined( $auth_code ) && $old_refresh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $auth_code and $old_refresh_token) 0 8 8
Condition66%2/3
not defined $auth_code and $old_refresh_token
!ll&&!rl&&r
260
MC/DC0%0/2
not defined $auth_code and $old_refresh_token
not defined $auth_code $old_refresh_token
Truth table66%2/3
not(A) and B
A= not defined $auth_codeB= $old_refresh_token
ABresult
0X0
100
111
200  
201 # must have generated an access token via a refresh token so revoke the old
202 # access token and refresh token and update the auth_codes hash to store the
203 # new one (also copy across scopes if missing)
204 0 $auth_code = $self->refresh_tokens->{ $old_refresh_token }{ auth_code };
205  
206 0 my $prev_access_token = $self->refresh_tokens->{ $old_refresh_token }{ access_token };
207  
208 # access tokens can be revoked, whilst refresh tokens can remain so we
209 # need to get the data from the refresh token as the access token may
210 # no longer exist at the point that the refresh token is used
211 0 ▶ $scope //= $self->refresh_tokens->{ $old_refresh_token }{ scope };
Condition0%0/3
$scope //= $self->refresh_tokens->{$old_refresh_token}{"scope"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$scope //= $self->refresh_tokens->{$old_refresh_token}{"scope"}
$scope $self->refresh_tokens->{$old_refresh_token}{"scope"}
Truth table0%0/3
A //= B
A= $scopeB= $self->refresh_tokens->{$old_refresh_token}{"scope"}
ABresult
1X1
011
000
212  
213 0 $self->_revoke_access_token( $prev_access_token );
214 }
215  
216 8 ▶ delete( $self->refresh_tokens->{ $old_refresh_token } )
Branch: 1 branch
BranchTrueFalseTotal
if $old_refresh_token 0 8 8
217 if $old_refresh_token;
218  
219 8 ▶ $self->access_tokens->{ $access_token } = {
Condition100%2/2
$refresh_token // undef
l!l
44
MC/DC100%1/1
$refresh_token // undef
$refresh_token
Truth table100%2/2
A
A= $refresh_token
Aresult
11
00
220 scope => $scope,
221 expires => time + $expires_in,
222 refresh_token => $refresh_token // undef,
223 client_id => $c_id,
224 };
225  
226 8 ▶ if ( $refresh_token ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($refresh_token) 4 4 8
227  
228 4 ▶ $self->refresh_tokens->{ $refresh_token } = {
Branch: 1 branch
BranchTrueFalseTotal
$self->_uses_auth_codes ? : 2 2 4
229 scope => $scope,
230 client_id => $c_id,
231 access_token => $access_token,
232 ( $self->_uses_auth_codes ? ( auth_code => $auth_code ) : () ),
233 };
234 }
235  
236 8 ▶ if ( $self->_uses_auth_codes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_uses_auth_codes) 2 6 8
237 2 $self->auth_codes->{ $auth_code }{ access_token } = $access_token;
238 }
239  
240 8 return $c_id;
241 }
242  
243 62 ▶sub _verify_access_token {
Subroutine _verify_access_token: called CC=14 SCAR=27.5
244 62 my ( $self, %args ) = @_;
245 62 ▶ return $self->_verify_access_token_jwt( %args ) if $self->jwt_secret;
Branch: 1 branch
BranchTrueFalseTotal
if $self->jwt_secret 32 30 62
246  
247 my ( $a_token, $scopes_ref, $is_refresh_token ) =
248 30 @args{ qw/ access_token scopes is_refresh_token / };
249  
250 30 ▶ if ( $is_refresh_token
Branch: 2 branches
BranchTrueFalseTotal
if ($is_refresh_token and exists $self->refresh_tokens->{$a_token}) { } 8 22 30
elsif (exists $self->access_tokens->{$a_token}) { } 16 6 22
Condition100%3/3
$is_refresh_token and exists $self->refresh_tokens->{$a_token}
!ll&&!rl&&r
1848
MC/DC100%2/2
$is_refresh_token and exists $self->refresh_tokens->{$a_token}
$is_refresh_token exists $self->refresh_tokens->{$a_token}
Truth table100%3/3
A and B
A= $is_refresh_tokenB= exists $self->refresh_tokens->{$a_token}
ABresult
0X0
100
111
251 && exists( $self->refresh_tokens->{ $a_token } ) )
252 {
253  
254 8 ▶ if ( $scopes_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scopes_ref) 8 0 8
255 8 ▶ foreach my $scope ( @{ $scopes_ref // [] } ) {
Condition50%1/2
$scopes_ref // []
l!l
80
MC/DC0%0/1
$scopes_ref // []
$scopes_ref
Truth table50%1/2
A
A= $scopes_ref
Aresult
11
00
256 return ( 0, 'invalid_grant' )
257 16 ▶ if !$self->_has_scope( $scope, $self->refresh_tokens->{ $a_token }{ scope } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_scope($scope, $self->refresh_tokens->{$a_token}{"scope"}) 0 16 16
258 }
259 }
260  
261 return (
262 $self->refresh_tokens->{ $a_token },
263 undef,
264 $self->refresh_tokens->{ $a_token }{ scope },
265 $self->refresh_tokens->{ $a_token }{ user_id },
266 8 );
267 }
268 elsif ( exists( $self->access_tokens->{ $a_token } ) ) {
269  
270 16 ▶ if ( $self->access_tokens->{ $a_token }{ expires } <= time ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->access_tokens->{$a_token}{'expires'} <= time) { } 0 16 16
elsif ($scopes_ref) { } 16 0 16
271 0 $self->_revoke_access_token( $a_token );
272 0 return ( 0, 'invalid_grant' );
273 }
274 elsif ( $scopes_ref ) {
275  
276 16 ▶ foreach my $scope ( @{ $scopes_ref // [] } ) {
Condition50%1/2
$scopes_ref // []
l!l
160
MC/DC0%0/1
$scopes_ref // []
$scopes_ref
Truth table50%1/2
A
A= $scopes_ref
Aresult
11
00
277 return ( 0, 'invalid_grant' )
278 24 ▶ if !$self->_has_scope( $scope, $self->access_tokens->{ $a_token }{ scope } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_scope($scope, $self->access_tokens->{$a_token}{"scope"}) 8 16 24
279 }
280  
281 }
282  
283 return (
284 $self->access_tokens->{ $a_token },
285 undef,
286 $self->access_tokens->{ $a_token }{ scope },
287 $self->access_tokens->{ $a_token }{ user_id },
288 8 );
289 }
290  
291 6 return ( 0, 'invalid_grant' );
292 }
293  
294 120 ▶sub _has_scope {
Subroutine _has_scope: called CC=2 SCAR=7.0
295 120 my ( $self, $scope, $available_scopes ) = @_;
296 120 ▶ return scalar grep { $_ eq $scope } @{ $available_scopes // [] };
Condition50%1/2
$available_scopes // []
l!l
1200
MC/DC0%0/1
$available_scopes // []
$available_scopes
Truth table50%1/2
A
A= $available_scopes
Aresult
11
00
297 }
298  
299 52 ▶sub _verify_access_token_jwt {
Subroutine _verify_access_token_jwt: called CC=10 SCAR=24.9
300 52 my ( $self, %args ) = @_;
301  
302 my ( $access_token, $scopes_ref, $is_refresh_token ) =
303 52 @args{ qw/ access_token scopes is_refresh_token / };
304  
305 52 my $access_token_payload;
306  
307 my $invalid_jwt;
308 52 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
309 52 $access_token_payload = decode_jwt(
310 alg => $self->jwt_algorithm,
311 key => $self->jwt_secret,
312 token => $access_token,
313 );
314 }
315 16 ▶ catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
316 16 $invalid_jwt = 1;
317 52 };
318 52 ▶ return ( 0, 'invalid_grant' ) if $invalid_jwt;
Branch: 1 branch
BranchTrueFalseTotal
if $invalid_jwt 16 36 52
319  
320 36 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($access_token_payload and $access_token_payload->{"type"} eq "access" || $is_refresh_token && $access_token_payload->{"type"} eq "refresh") 36 0 36
Condition44%4/9
$access_token_payload and $access_token_payload->{"type"} eq "access" || $is_refresh_token && $access_token_payload->{"type"} eq "refresh"
!ll&&!rl&&r
0036
$access_token_payload->{"type"} eq "access" or $is_refresh_token and $access_token_payload->{"type"} eq "refresh"
l!l&&r!l&&!r
2880
$is_refresh_token and $access_token_payload->{"type"} eq "refresh"
!ll&&!rl&&r
008
MC/DC0%0/4
$access_token_payload and $access_token_payload->{"type"} eq "access" || $is_refresh_token && $access_token_payload->{"type"} eq "refresh"
$access_token_payload $access_token_payload->{"type"} eq "access" $is_refresh_token $access_token_payload->{"type"} eq "refresh"
Truth table40%2/5
A and B or C and D
A= $access_token_payloadB= $access_token_payload->{"type"} eq "access"C= $is_refresh_tokenD= $access_token_payload->{"type"} eq "refresh"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
321 $access_token_payload
322 && ( $access_token_payload->{ type } eq 'access'
323 || $is_refresh_token && $access_token_payload->{ type } eq 'refresh' )
324 )
325 {
326  
327 36 ▶ if ( $scopes_ref ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scopes_ref) 36 0 36
328 36 ▶ foreach my $scope ( @{ $scopes_ref // [] } ) {
Condition50%1/2
$scopes_ref // []
l!l
360
MC/DC0%0/1
$scopes_ref // []
$scopes_ref
Truth table50%1/2
A
A= $scopes_ref
Aresult
11
00
329 return ( 0, 'invalid_grant' )
330 60 ▶ if !$self->_has_scope( $scope, $access_token_payload->{ scopes } );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_has_scope($scope, $access_token_payload->{"scopes"}) 12 48 60
331 }
332 }
333  
334 24 return ( $access_token_payload, undef, $access_token_payload->{scopes} );
335 }
336  
337 0 return ( 0, 'invalid_grant' );
338 }
339  
340 2 ▶sub _revoke_access_token {
Subroutine _revoke_access_token: called CC=1 SCAR=0.0
341 2 my ( $self, $access_token ) = @_;
342 2 delete( $self->access_tokens->{ $access_token } );
343 }
344  
345 46 ▶sub get_access_token_ttl {
Subroutine get_access_token_ttl: called CC=2 SCAR=6.9
Pod undocumented
346 46 my ( $self, %args ) = @_;
347  
348 46 ▶ return ref $self->access_token_ttl eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $self->access_token_ttl eq 'CODE' ? : 2 44 46
349 ? $self->access_token_ttl->( %args )
350 : $self->access_token_ttl;
351 }
352  
353 31 ▶sub token {
Subroutine token: called CC=9 SCAR=22.0
Pod undocumented
354 31 my ( $self, %args ) = @_;
355  
356 my ( $client_id, $scopes, $type, $redirect_uri, $user_id, $claims ) =
357 31 @args{ qw/ client_id scopes type redirect_uri user_id jwt_claims_cb / };
358  
359 31 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_uses_auth_codes and $type eq "auth") 0 31 31
Condition66%2/3
not $self->_uses_auth_codes and $type eq "auth"
!ll&&!rl&&r
12190
MC/DC0%0/2
not $self->_uses_auth_codes and $type eq "auth"
not $self->_uses_auth_codes $type eq "auth"
Truth table66%2/3
not(A) and B
A= not $self->_uses_auth_codesB= $type eq "auth"
ABresult
0X0
100
111
360 ! $self->_uses_auth_codes
361 && $type eq 'auth'
362 ) {
363 0 croak "Invalid type for ->token ($type)";
364 }
365  
366 31 ▶ my $ttl = $type eq 'auth' ? $self->auth_code_ttl : $self->get_access_token_ttl(
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'auth' ? : 4 27 31
367 scopes => $scopes,
368 client_id => $client_id,
369 );
370  
371 31 ▶ undef( $ttl ) if $type eq 'refresh';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "refresh" 8 23 31
372 31 my $code;
373  
374 31 ▶ if ( !$self->jwt_secret ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->jwt_secret) { } 14 17 31
375 14 my ( $sec, $usec ) = gettimeofday;
376 14 $code = encode_base64( join( '-', $sec, $usec, rand(), random_string( 30 ) ), '' );
377 }
378 else {
379 17 ▶ if ( $self->jwt_algorithm =~ /none/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->jwt_algorithm =~ /none/i) 1 16 17
380 1 croak "A jwt_algorithm of 'none' is not supported as this is insecure";
381 }
382  
383 16 my $jti = random_string( 32 );
384  
385 16 ▶ $code = encode_jwt(
Branch: 2 branches
BranchTrueFalseTotal
$ttl ? : 12 4 16
$claims ? : 2 14 16
386 allow_none => 0, # do NOT allow the "none" algorithm, as this is massively insecure
387 # we actually already check this above, but this is here a backup
388 alg => $self->jwt_algorithm,
389 key => $self->jwt_secret,
390 enc => $self->jwt_encoding,
391  
392 ( $ttl ? ( relative_exp => $ttl ) : () ),
393 auto_iat => 1,
394  
395 # https://tools.ietf.org/html/rfc7519#section-4
396 payload => {
397 # Registered Claim Names
398 aud => $redirect_uri, # the "audience"
399 jti => $jti,
400  
401 # Private Claim Names
402 user_id => $user_id,
403 client => $client_id,
404 type => $type,
405 scopes => $scopes,
406  
407 ( $claims
408 ? ( $claims->({
409 user_id => $user_id,
410 client_id => $client_id,
411 type => $type,
412 scopes => $scopes,
413 redirect_uri => $redirect_uri,
414 jti => $jti,
415 }) )
416 : ()
417 ),
418 },
419 );
420 }
421  
422 30 return $code;
423 }
424  
425 10 __PACKAGE__->meta->make_immutable;
↑ Summary AuthorizationServer/ImplicitGrant.pm »