Client/Role/ClientAuthenticationHelper.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 92.8% 13 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 90.8% 79 / 87 CC 10 SCAR 13.1
CC
10
Cov
94%
_build_client_auth_arguments
7.1
_build_client_assertion
4.0
BEGIN
1.0
CRAP 3.7
« Client/Utils.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  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 OIDC::Client::Role::ClientAuthenticationBuilder - Client Authentication Builder
17  
18 =head1 DESCRIPTION
19  
20 This Moose role covers private methods for building client authentication data.
21  
22 =cut
23  
24  
25 5 requires qw(log_msg
26 id
27 secret
28 private_key
29 client_assertion_lifetime
30 client_assertion_audience
31 generate_uuid_string
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 ▶sub _build_client_auth_arguments ($self, $method, $url) {
Subroutine _build_client_auth_arguments: called CC=7 SCAR=19.6
40  
41 29 my (%headers, %form);
42  
43 29 ▶ if ($method eq 'client_secret_basic') {
Branch: 5 branches
BranchTrueFalseTotal
if ($method eq 'client_secret_basic') { } 12 17 29
elsif ($method eq 'client_secret_post') { } 8 9 17
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 8 $form{client_id} = $self->id;
48 8 $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 29 return (\%headers, \%form);
68 }
69  
70  
71 ▶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 = $self->generate_uuid_string();
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/Utils.pm ↑ Summary Client/Role/AttributesManager.pm »