| 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
| |||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||
| 90 | : $self->client_secret_jwt_encoding_options; | ||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||
| 92 | 7 | ▶ | return Crypt::JWT::encode_jwt( | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 93 | %$jwt_encoding_options, | ||||||||||||||||||||||||||
| 94 | payload => \%claims, | ||||||||||||||||||||||||||
| 95 | key => $use_private_key ? $self->private_key : $self->secret, | ||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||
| 100 | 5 | 1; | |||||||||||||||||||||||||