Client/Role/ClientAuthenticationHelper.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 91.2% 83 / 91 CC 10 SCAR 12.8
CC
10
Cov
95%
_build_client_auth_arguments
7.1
_build_client_assertion
4.0
BEGIN
1.0
CRAP 3.6
« Client/Plugin.pm ↑ Summary Client/Role/AttributesManager.pm »
1 package OIDC::Client::Role::ClientAuthenticationHelper;
2 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Mojo::Util qw(b64_encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Crypt::JWT ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use OIDC::Client::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =encoding utf8
14  
15 =head1 NAME
16  
17 OIDC::Client::Role::ClientAuthenticationBuilder - Client Authentication Builder
18  
19 =head1 DESCRIPTION
20  
21 This Moose role covers private methods for building client authentication data.
22  
23 =cut
24  
25  
26 5 requires qw(log_msg
27 id
28 secret
29 private_key
30 client_assertion_lifetime
31 client_assertion_audience
32 private_key_jwt_encoding_options
33 client_secret_jwt_encoding_options);
34  
35  
36 5 Readonly my $CLIENT_ASSERTION_TYPE => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer';
37  
38  
39 30 ▶sub _build_client_auth_arguments ($self, $method, $url) {
Subroutine _build_client_auth_arguments: called CC=7 SCAR=19.6
40  
41 30 my (%headers, %form);
42  
43 30 ▶ if ($method eq 'client_secret_basic') {
Branch: 5 branches
BranchTrueFalseTotal
if ($method eq 'client_secret_basic') { } 12 18 30
elsif ($method eq 'client_secret_post') { } 9 9 18
elsif ($method eq 'client_secret_jwt') { } 3 6 9
elsif ($method eq 'private_key_jwt') { } 4 2 6
elsif ($method eq 'tls_client_auth' or $method eq 'none') { } 2 0 2
44 12 $headers{Authorization} = 'Basic ' . b64_encode(join(':', $self->id, $self->secret), '');
45 }
46 elsif ($method eq 'client_secret_post') {
47 9 $form{client_id} = $self->id;
48 9 $form{client_secret} = $self->secret;
49 }
50 elsif ($method eq 'client_secret_jwt') {
51 3 $form{client_id} = $self->id;
52 3 $form{client_assertion_type} = $CLIENT_ASSERTION_TYPE;
53 3 $form{client_assertion} = $self->_build_client_assertion(0, $url);
54 }
55 elsif ($method eq 'private_key_jwt') {
56 4 $form{client_id} = $self->id;
57 4 $form{client_assertion_type} = $CLIENT_ASSERTION_TYPE;
58 4 $form{client_assertion} = $self->_build_client_assertion(1, $url);
59 }
60 ▶ elsif ($method eq 'tls_client_auth' || $method eq 'none') {
Condition66%2/3
$method eq "tls_client_auth" or $method eq "none"
l!l&&r!l&&!r
110
MC/DC0%0/2
$method eq "tls_client_auth" or $method eq "none"
$method eq "tls_client_auth" $method eq "none"
Truth table66%2/3
A or B
A= $method eq "tls_client_auth"B= $method eq "none"
ABresult
1X1
011
000
61 2 $form{client_id} = $self->id;
62 }
63 else {
64 0 croak("Unsupported client auth method: $method");
65 }
66  
67 30 return (\%headers, \%form);
68 }
69  
70  
71 7 ▶sub _build_client_assertion ($self, $use_private_key, $url) {
Subroutine _build_client_assertion: called CC=4 SCAR=13.9
72  
73 7 $self->log_msg(debug => 'OIDC: building client assertion');
74  
75 7 my $now = time;
76 7 my $exp = $now + $self->client_assertion_lifetime;
77 7 ▶ my $aud = $self->client_assertion_audience // $url;
Condition66%2/3
$self->client_assertion_audience // $url
l!l&&r!l&&!r
250
MC/DC0%0/2
$self->client_assertion_audience // $url
$self->client_assertion_audience $url
Truth table66%2/3
A // B
A= $self->client_assertion_audienceB= $url
ABresult
1X1
011
000
78 7 my $jti = OIDC::Client::Utils::generate_jti();
79  
80 7 my %claims = (
81 iss => $self->id,
82 sub => $self->id,
83 aud => $aud,
84 jti => $jti,
85 iat => $now,
86 exp => $exp,
87 );
88  
89 7 ▶ my $jwt_encoding_options = $use_private_key ? $self->private_key_jwt_encoding_options
Branch: 1 branch
BranchTrueFalseTotal
$use_private_key ? : 4 3 7
90 : $self->client_secret_jwt_encoding_options;
91  
92 7 ▶ return Crypt::JWT::encode_jwt(
Branch: 1 branch
BranchTrueFalseTotal
$use_private_key ? : 4 3 7
93 %$jwt_encoding_options,
94 payload => \%claims,
95 key => $use_private_key ? $self->private_key : $self->secret,
96 );
97 }
98  
99  
100 5 1;
« Client/Plugin.pm ↑ Summary Client/Role/AttributesManager.pm »