Authentik/OIDC.pm

filter: Statementstmt 99.4% 184 / 185 Branchbran 88.8% 64 / 72 Conditioncond 86.6% 39 / 45 MC/DCmcdc 76.9% 20 / 26 Subroutinesub 97.7% 43 / 44 Podpod 100% 23 / 23 totaltotal 94.4% 373 / 395 CC 53 SCAR 21.1
CC
53
Cov
95%
verify_token_f
25.0
authorization_url_f
5.0
_token_call_f
4.1
CRAP 8.2
↑ Summary Authentik/API.pm »
1 package Net::Async::Authentik::OIDC;
2  
3 # ABSTRACT: OpenID Connect against one authentik application, asynchronously
4  
5 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 with 'Net::Async::Authentik::Role::HTTP';
7 8 with 'WWW::Authentik::Role::HTTP';
8 8 ▶use Crypt::JWT qw( decode_jwt );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Types::Standard qw( ArrayRef CodeRef Int Object Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 8 our $VERSION = '0.001';
16  
17  
18 8 has application_url => ( is => 'ro', isa => Str | Types::Standard::Undef );
19  
20  
21 8 has http => ( is => 'ro', isa => Object, required => 1 );
22  
23  
24 8 has client_id => ( is => 'ro', isa => Str, predicate => 'has_client_id' );
25  
26  
27 has algorithms => (
28 is => 'ro',
29 isa => ArrayRef[Str],
30 19 ▶ default => sub { [qw( RS256 RS384 RS512 PS256 PS384 PS512 ES256 ES384 ES512 )] }
Subroutine __ANON__: called CC=1 SCAR=0.0
31 8 );
32 8 has jwks_min_age => ( is => 'ro', isa => Int, default => 60 );
33 0 ▶has now => ( is => 'ro', isa => CodeRef, default => sub { sub { time } } );
Subroutine __ANON__: called CC=1 SCAR=0.4
Subroutine __ANON__: not called CC=1 SCAR=0.4
34  
35  
36 8 has _discovery => ( is => 'rw', init_arg => undef );
37 8 has _jwks => ( is => 'rw', init_arg => undef );
38 8 has _jwks_fetched => ( is => 'rw', init_arg => undef );
39 19 ▶has _in_flight => ( is => 'ro', init_arg => undef, default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
40  
41 # One fetch for everybody who asks while it is under way, each with a view of
42 # its own so that cancelling one does not cancel the fetch.
43 87 ▶sub _shared {
Subroutine _shared: called CC=3 SCAR=11.0
44 87 my ( $self, $key, $start ) = @_;
45 87 my $in_flight = $self->_in_flight;
46 87 ▶ unless ( $in_flight->{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_flight->{$key}) 21 66 87
47 21 ▶ my $future = $start->()->on_ready( sub { delete $in_flight->{$key} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
48 21 ▶ return $future if $future->is_ready;
Branch: 1 branch
BranchTrueFalseTotal
if $future->is_ready 14 7 21
49 7 $in_flight->{$key} = $future;
50 }
51 73 return $in_flight->{$key}->without_cancel;
52 }
53  
54 247 ▶sub _url {
Subroutine _url: called CC=3 SCAR=11.0
55 247 my ( $self ) = @_;
56 247 ▶ return $self->application_url if defined $self->application_url && length $self->application_url;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->application_url and length $self->application_url 246 1 247
Condition66%2/3
defined $self->application_url and length $self->application_url
!ll&&!rl&&r
10246
MC/DC50%1/2
defined $self->application_url and length $self->application_url
defined $self->application_url length $self->application_url
Truth table66%2/3
A and B
A= defined $self->application_urlB= length $self->application_url
ABresult
0X0
100
111
57 1 return;
58 }
59  
60 135 ▶sub discovery_f {
Subroutine discovery_f: called CC=3 SCAR=11.0
Pod documented
61 135 my ( $self ) = @_;
62 135 ▶ return $self->fail_validation( __PACKAGE__.' needs an application slug' ) unless $self->_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_url 1 134 135
63 134 ▶ return Future->done( $self->_discovery ) if $self->_discovery;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_discovery 98 36 134
64 36 ▶ return $self->_shared( discovery => sub { $self->_fetch_discovery_f } );
Subroutine __ANON__: called CC=1 SCAR=0.0
65 }
66  
67 12 ▶async sub _fetch_discovery_f {
Subroutine _fetch_discovery_f: called CC=2 SCAR=7.0
68 12 my ( $self ) = @_;
69 12 my $data = ( await $self->send_request_f( GET => $self->_url.'/.well-known/openid-configuration' ) )->{data};
70 9 ▶ die $self->validation_error_class->new( message => 'discovery for '.$self->_url.' returned no JSON object' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 9 9
71 unless ref $data eq 'HASH';
72 9 return $self->_discovery($data);
73 8 }
74  
75  
76 129 ▶async sub endpoint_f {
Subroutine endpoint_f: called CC=2 SCAR=6.9
Pod documented
77 129 my ( $self, $name ) = @_;
78 129 my $url = ( await $self->discovery_f )->{$name};
79 129 ▶ die $self->validation_error_class->new( message => 'the discovery document of '.$self->_url.' has no '.$name )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url 1 128 129
80 unless defined $url;
81 128 return $url;
82 8 }
83  
84  
85 79 ▶sub issuer_f { $_[0]->endpoint_f('issuer') }
Subroutine issuer_f: called CC=1 SCAR=0.0
Pod documented
86 3 ▶sub authorization_endpoint_f { $_[0]->endpoint_f('authorization_endpoint') }
Subroutine authorization_endpoint_f: called CC=1 SCAR=0.0
Pod documented
87 21 ▶sub token_endpoint_f { $_[0]->endpoint_f('token_endpoint') }
Subroutine token_endpoint_f: called CC=1 SCAR=0.0
Pod documented
88 5 ▶sub userinfo_endpoint_f { $_[0]->endpoint_f('userinfo_endpoint') }
Subroutine userinfo_endpoint_f: called CC=1 SCAR=0.0
Pod documented
89 4 ▶sub introspection_endpoint_f { $_[0]->endpoint_f('introspection_endpoint') }
Subroutine introspection_endpoint_f: called CC=1 SCAR=0.0
Pod documented
90 3 ▶sub revocation_endpoint_f { $_[0]->endpoint_f('revocation_endpoint') }
Subroutine revocation_endpoint_f: called CC=1 SCAR=0.0
Pod documented
91 1 ▶sub end_session_endpoint_f { $_[0]->endpoint_f('end_session_endpoint') }
Subroutine end_session_endpoint_f: called CC=1 SCAR=0.0
Pod documented
92 2 ▶sub device_endpoint_f { $_[0]->endpoint_f('device_authorization_endpoint') }
Subroutine device_endpoint_f: called CC=1 SCAR=0.0
Pod documented
93 10 ▶sub jwks_uri_f { $_[0]->endpoint_f('jwks_uri') }
Subroutine jwks_uri_f: called CC=1 SCAR=0.0
Pod documented
94  
95  
96 76 ▶sub jwks_f {
Subroutine jwks_f: called CC=4 SCAR=13.9
Pod documented
97 76 my ( $self, %opt ) = @_;
98 76 ▶ return $self->fail_validation( __PACKAGE__.' needs an application slug' ) unless $self->_url;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_url 0 76 76
99 76 ▶ return Future->done( $self->_jwks ) if $self->_jwks && !$opt{force_refresh};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_jwks and not $opt{"force_refresh"} 25 51 76
Condition100%3/3
$self->_jwks and not $opt{"force_refresh"}
!ll&&!rl&&r
282325
MC/DC100%2/2
$self->_jwks and not $opt{"force_refresh"}
$self->_jwks not $opt{"force_refresh"}
Truth table100%3/3
A and not(B)
A= $self->_jwksB= not $opt{"force_refresh"}
ABresult
0X0
100
111
100 9 ▶ return $self->_shared( jwks => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 # counted from the start, so that verifications already under way see it
102 9 $self->_jwks_fetched( $self->now->() );
103 9 $self->_fetch_jwks_f;
104 51 } );
105 }
106  
107 9 ▶async sub _fetch_jwks_f {
Subroutine _fetch_jwks_f: called CC=2 SCAR=7.0
108 9 my ( $self ) = @_;
109 9 my $uri = await $self->jwks_uri_f;
110 9 my $data = ( await $self->send_request_f( GET => $uri ) )->{data};
111 # without this the cache stays empty and every verification fetches again,
112 # which is what the sibling above already guards against
113 9 ▶ die $self->validation_error_class->new( message => 'the keys of '.$self->_url.' came back as no JSON object' )
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data eq "HASH" 0 9 9
114 unless ref $data eq 'HASH';
115 9 return $self->_jwks($data);
116 8 }
117  
118  
119 23 ▶async sub issuer_names_the_application_f {
Subroutine issuer_names_the_application_f: called CC=2 SCAR=6.9
Pod documented
120 23 my ( $self ) = @_;
121 23 ▶ return ( await $self->issuer_f ) eq $self->_url.'/' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
<custom op await> eq $self->_url . '/' ? : 21 2 23
122 8 }
123  
124  
125 58 ▶async sub verify_token_f {
Subroutine verify_token_f: called CC=25 SCAR=32.2
Pod documented
126 58 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 2, @_ );
127 58 ▶ return await $_[0]->fail_validation('verify_token_f: the arguments after the first 1 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 57 58
128 57 my ( $self, $token ) = @_;
129 57 my %opt = %$pairs;
130 57 ▶ die $self->validation_error_class->new( message => 'verify_token needs a token' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token and length $token 2 55 57
Condition100%3/3
defined $token and length $token
!ll&&!rl&&r
1155
MC/DC100%2/2
defined $token and length $token
defined $token length $token
Truth table100%3/3
A and B
A= defined $tokenB= length $token
ABresult
0X0
100
111
131 unless defined $token && length $token;
132 die $self->validation_error_class->new( message => "verify_token: type must be 'access' or 'id'" )
133 55 ▶ if defined $opt{type} && $opt{type} ne 'access' && $opt{type} ne 'id';
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt{"type"} and $opt{"type"} ne "access" and $opt{"type"} ne "id" 1 54 55
Condition100%6/6
defined $opt{"type"} and $opt{"type"} ne "access" and $opt{"type"} ne "id"
!ll&&!rl&&r
5221
defined $opt{"type"} and $opt{"type"} ne "access"
!ll&&!rl&&r
5023
MC/DC100%3/3
defined $opt{"type"} and $opt{"type"} ne "access" and $opt{"type"} ne "id"
defined $opt{"type"} $opt{"type"} ne "access" $opt{"type"} ne "id"
Truth table100%4/4
A and B and C
A= defined $opt{"type"}B= $opt{"type"} ne "access"C= $opt{"type"} ne "id"
ABCresult
0XX0
10X0
1100
1111
134 my $audience = exists $opt{audience} ? $opt{audience}
135 54 ▶ : $self->has_client_id ? $self->client_id
Branch: 2 branches
BranchTrueFalseTotal
exists $opt{'audience'} ? : 4 50 54
$self->has_client_id ? : 2 48 50
136 : undef;
137 54 my $issuer = await $self->issuer_f;
138 # Every provider of one authentik signs with the same key, so the issuer is
139 # all that separates two applications - and with issuer_mode: global it is
140 # the bare instance URL, the same for all of them. Then only the audience
141 # tells them apart, and verifying without one would accept any token the
142 # instance ever issued.
143 die $self->validation_error_class->new( message => 'verify_token cannot tell this application apart: '
144 .'the provider issues tokens as "'.$issuer.'", which does not name the application, so a token '
145 .'of any other application of this authentik would pass. Give an audience, set client_id on the client, '
146 .'or say any_audience => 1 if you really mean to accept them all.' )
147 54 ▶ if !defined $audience && !$opt{any_audience} && !await( $self->issuer_names_the_application_f );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $audience or $opt{"any_audience"} or <custom op await> 1 53 54
Condition100%6/6
defined $audience or $opt{"any_audience"} or <custom op await>
l!l&&r!l&&!r
33201
defined $audience or $opt{"any_audience"}
l!l&&r!l&&!r
62721
MC/DC100%3/3
defined $audience or $opt{"any_audience"} or <custom op await>
defined $audience $opt{"any_audience"} <custom op await>
Truth table100%4/4
A or B or C
A= defined $audienceB= $opt{"any_audience"}C= <custom op await>
ABCresult
1XX1
01X1
0011
0000
148 53 ▶ my %check = (
Branch: 1 branch
BranchTrueFalseTotal
defined $audience ? : 6 47 53
149 token => $token,
150 verify_iss => $issuer,
151 verify_exp => 1,
152 accepted_alg => $self->algorithms,
153 decode_payload => 1,
154 defined $audience ? ( verify_aud => $audience ) : ()
155 );
156 53 my $keys = await $self->jwks_f;
157 53 my $claims = eval { decode_jwt( %check, kid_keys => $keys ) };
158 53 my $error = $@;
159 # a key authentik rotated in since the keys were fetched: fetch them again,
160 # but only for that reason, and not more often than jwks_min_age allows. A
161 # fetch already under way counts, or twenty concurrent verifications would
162 # each want their own.
163 53 ▶ my $again = $self->_in_flight->{jwks} || $self->now->() - ( $self->_jwks_fetched // 0 ) >= $self->jwks_min_age;
Condition80%4/5
$self->_in_flight->{'jwks'} || $self->now->() - ($self->_jwks_fetched // 0) >= $self->jwks_min_age
l!l&&r!l&&!r
19430
$self->_jwks_fetched // 0
l!l
340
MC/DC100%2/2
$self->_in_flight->{'jwks'} || $self->now->() - ($self->_jwks_fetched // 0) >= $self->jwks_min_age
$self->_in_flight->{'jwks'} $self->now->() - ($self->_jwks_fetched // 0) >= $self->jwks_min_age
MC/DC0%0/1
$self->_jwks_fetched // 0
$self->_jwks_fetched
Truth table100%3/3
A || B
A= $self->_in_flight->{'jwks'}B= $self->now->() - ($self->_jwks_fetched // 0) >= $self->jwks_min_age
ABresult
1X1
011
000
Truth table50%1/2
A
A= $self->_jwks_fetched
Aresult
11
00
164 53 ▶ if ( !$claims && $error =~ /kid_keys lookup failed/ && $again ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $claims and $error =~ /kid_keys lookup failed/ and $again) 23 30 53
Condition100%6/6
not $claims and $error =~ /kid_keys lookup failed/ and $again
!ll&&!rl&&r
191123
not $claims and $error =~ /kid_keys lookup failed/
!ll&&!rl&&r
11834
MC/DC100%3/3
not $claims and $error =~ /kid_keys lookup failed/ and $again
not $claims $error =~ /kid_keys lookup failed/ $again
Truth table100%4/4
not(A) and B and C
A= not $claimsB= $error =~ /kid_keys lookup failed/C= $again
ABCresult
0XX0
10X0
1100
1111
165 23 $keys = await $self->jwks_f( force_refresh => 1 );
166 23 $claims = eval { decode_jwt( %check, kid_keys => $keys ) };
167 23 $error = $@;
168 }
169 53 ▶ $self->_reject( $error =~ s/ at \S+ line \d+.*//sr ) unless $claims;
Branch: 1 branch
BranchTrueFalseTotal
unless $claims 41 12 53
170 12 ▶ if ( defined $opt{type} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opt{"type"}) 4 8 12
171 4 ▶ my $looks_like_access = exists $claims->{scope} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $claims->{'scope'} ? : 2 2 4
172 $self->_reject('not an access token: it carries no scope claim')
173 4 ▶ if $opt{type} eq 'access' && !$looks_like_access;
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"type"} eq "access" and not $looks_like_access 1 3 4
Condition100%3/3
$opt{"type"} eq "access" and not $looks_like_access
!ll&&!rl&&r
211
MC/DC100%2/2
$opt{"type"} eq "access" and not $looks_like_access
$opt{"type"} eq "access" not $looks_like_access
Truth table100%3/3
A and not(B)
A= $opt{"type"} eq "access"B= not $looks_like_access
ABresult
0X0
100
111
174 $self->_reject('not an ID token: it carries a scope claim')
175 3 ▶ if $opt{type} eq 'id' && $looks_like_access;
Branch: 1 branch
BranchTrueFalseTotal
if $opt{"type"} eq "id" and $looks_like_access 1 2 3
Condition100%3/3
$opt{"type"} eq "id" and $looks_like_access
!ll&&!rl&&r
111
MC/DC100%2/2
$opt{"type"} eq "id" and $looks_like_access
$opt{"type"} eq "id" $looks_like_access
Truth table100%3/3
A and B
A= $opt{"type"} eq "id"B= $looks_like_access
ABresult
0X0
100
111
176 }
177 10 return $claims;
178 8 }
179  
180 43 ▶sub _reject {
Subroutine _reject: called CC=1 SCAR=0.0
181 43 my ( $self, $why ) = @_;
182 43 die $self->validation_error_class->new( message => 'token rejected: '.$why );
183 }
184  
185  
186 4 ▶async sub userinfo_f {
Subroutine userinfo_f: called CC=3 SCAR=11.8
Pod documented
187 4 my ( $self, $access_token ) = @_;
188 4 ▶ die $self->validation_error_class->new( message => 'userinfo needs an access token' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $access_token and length $access_token 0 4 4
Condition33%1/3
defined $access_token and length $access_token
!ll&&!rl&&r
004
MC/DC0%0/2
defined $access_token and length $access_token
defined $access_token length $access_token
Truth table33%1/3
A and B
A= defined $access_tokenB= length $access_token
ABresult
0X0
100
111
189 unless defined $access_token && length $access_token;
190 4 my $endpoint = await $self->userinfo_endpoint_f;
191 4 return ( await $self->send_request_f( GET => $endpoint, bearer => $access_token ) )->{data};
192 8 }
193  
194 4 ▶async sub introspect_f {
Subroutine introspect_f: called CC=3 SCAR=11.0
Pod documented
195 4 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 2, @_ );
196 4 ▶ return await $_[0]->fail_validation('introspect_f: the arguments after the first 1 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 3 4
197 3 my ( $self, $token ) = @_;
198 3 my %client = %$pairs;
199 return await $self->_token_call_f( await( $self->introspection_endpoint_f ),
200 3 ▶ { token => $token, defined $client{token_type_hint} ? ( token_type_hint => $client{token_type_hint} ) : () }, %client );
Branch: 1 branch
BranchTrueFalseTotal
defined $client{'token_type_hint'} ? : 0 3 3
201 8 }
202  
203 3 ▶async sub revoke_f {
Subroutine revoke_f: called CC=3 SCAR=11.0
Pod documented
204 3 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 2, @_ );
205 3 ▶ return await $_[0]->fail_validation('revoke_f: the arguments after the first 1 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
206 2 my ( $self, $token ) = @_;
207 2 my %client = %$pairs;
208 await $self->_token_call_f( await( $self->revocation_endpoint_f ),
209 2 ▶ { token => $token, defined $client{token_type_hint} ? ( token_type_hint => $client{token_type_hint} ) : () }, %client );
Branch: 1 branch
BranchTrueFalseTotal
defined $client{'token_type_hint'} ? : 0 2 2
210 2 return 1;
211 8 }
212  
213 9 ▶sub client_credentials_token_f { my ( $self, %arg ) = @_; $self->_grant_f( client_credentials => [qw( scope username password )], %arg ) }
Subroutine client_credentials_token_f: called CC=1 SCAR=0.0
Pod documented
214 3 ▶sub refresh_token_f { my ( $self, $refresh, %arg ) = @_; $self->_grant_f( refresh_token => [qw( refresh_token scope )], %arg, refresh_token => $refresh ) }
Subroutine refresh_token_f: called CC=1 SCAR=0.0
Pod documented
215 2 ▶sub exchange_authorization_code_f { my ( $self, %arg ) = @_; $self->_grant_f( authorization_code => [qw( code redirect_uri code_verifier )], %arg ) }
Subroutine exchange_authorization_code_f: called CC=1 SCAR=0.0
Pod documented
216 3 ▶sub device_token_f { my ( $self, %arg ) = @_; $self->_grant_f( 'urn:ietf:params:oauth:grant-type:device_code' => ['device_code'], %arg ) }
Subroutine device_token_f: called CC=1 SCAR=0.0
Pod documented
217  
218 2 ▶async sub device_authorization_f {
Subroutine device_authorization_f: called CC=3 SCAR=11.0
Pod documented
219 2 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
220 2 ▶ return await $_[0]->fail_validation('device_authorization_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 1 2
221 1 my ( $self ) = @_;
222 1 my %arg = %$pairs;
223 1 my $endpoint = await $self->device_endpoint_f;
224 return await $self->_token_call_f( $endpoint,
225 1 ▶ { defined $arg{scope} ? ( scope => $arg{scope} ) : () }, %arg );
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'scope'} ? : 1 0 1
226 8 }
227  
228  
229 5 ▶async sub authorization_url_f {
Subroutine authorization_url_f: called CC=5 SCAR=16.1
Pod documented
230 5 my ( $ok, $pairs ) = __PACKAGE__->pairs_or_fail( 1, @_ );
231 5 ▶ return await $_[0]->fail_validation('authorization_url_f: the arguments after the first 0 do not make pairs') unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 4 5
232 4 my ( $self ) = @_;
233 4 my %arg = %$pairs;
234 4 ▶ die $self->validation_error_class->new( message => 'authorization_url needs a client_id' ) unless defined $arg{client_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"client_id"} 1 3 4
235 3 ▶ die $self->validation_error_class->new( message => 'authorization_url needs a redirect_uri' ) unless defined $arg{redirect_uri};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"redirect_uri"} 1 2 3
236 2 my $uri = URI->new( await $self->authorization_endpoint_f );
237 $uri->query_form(
238 response_type => $arg{response_type} // 'code',
239 2 ▶ map { $_ => $arg{$_} } grep { defined $arg{$_} }
Condition50%1/2
$arg{"response_type"} // "code"
l!l
02
MC/DC0%0/1
$arg{"response_type"} // "code"
$arg{"response_type"}
Truth table50%1/2
A
A= $arg{"response_type"}
Aresult
11
00
240 qw( client_id redirect_uri scope state nonce prompt max_age acr_values
241 code_challenge code_challenge_method response_mode )
242 );
243 2 return $uri->as_string;
244 8 }
245  
246  
247 17 ▶async sub _grant_f {
Subroutine _grant_f: called CC=1 SCAR=0.0
248 17 my ( $self, $type, $fields, %arg ) = @_;
249 return await $self->_token_call_f( await( $self->token_endpoint_f ),
250 17 { grant_type => $type, map { $_ => $arg{$_} } grep { defined $arg{$_} } @$fields }, %arg );
251 8 }
252  
253 23 ▶async sub _token_call_f {
Subroutine _token_call_f: called CC=4 SCAR=14.1
254 23 my ( $self, $url, $form, %arg ) = @_;
255 23 ▶ die $self->validation_error_class->new( message => 'a client_id is needed' ) unless defined $arg{client_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"client_id"} 1 22 23
256 my %form = (
257 %$form,
258 client_id => $arg{client_id},
259 22 ▶ defined $arg{client_secret} ? ( client_secret => $arg{client_secret} ) : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $arg{'client_secret'} ? : 22 0 22
260 );
261 22 ▶ return ( await $self->send_request_f( POST => $url, form => \%form ) )->{data} // {};
Condition50%1/2
<custom op await>->{"data"} // {}
l!l
130
MC/DC0%0/1
<custom op await>->{"data"} // {}
<custom op await>->{"data"}
Truth table50%1/2
A
A= <custom op await>->{"data"}
Aresult
11
00
262 8 }
263  
264 8 1;
265  
266 __END__
↑ Summary Authentik/API.pm »