| 1 | package OIDC::Client::Role::ClaimsValidator; | ||||||||||||||||||||
| 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 Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use List::Util qw(any); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use OIDC::Client::Error::TokenValidation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =encoding utf8 | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | OIDC::Client::Role::ClaimsValidator - Claims Validator | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | This Moose role covers private methods for validating token claims. | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 5 | requires qw(audience | |||||||||||||||||||
| 25 | provider_metadata | ||||||||||||||||||||
| 26 | jwt_decoding_options); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 30 | ▶ | sub _validate_issuer ($self, $issuer) { | ||||||||||||||||||
|
Subroutine
_validate_issuer: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 30 | ▶ | defined $issuer | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'iss' claim is missing"); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | my $expected_issuer = $self->provider_metadata->{issuer} | ||||||||||||||||||||
| 35 | 29 | ▶ | or croak("OIDC: issuer not found in provider metadata"); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 29 | ▶ | $issuer eq $expected_issuer | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 39 | "OIDC: unexpected issuer, expected '$expected_issuer' but got '$issuer'" | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 27 | ▶ | sub _validate_audience ($self, $audience, $expected_audience) { | ||||||||||||||||||
|
Subroutine
_validate_audience: called CC=5 SCAR=16.2
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 27 | ▶ | defined $audience | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'aud' claim is missing"); | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 26 | ▶ | $expected_audience ||= $self->audience; | ||||||||||||||||||
|
Condition66%2/3
$expected_audience ||= $self->audience
MC/DC0%0/2
$expected_audience ||= $self->audience
$expected_audience
$self->audience
Truth table66%2/3
A ||= B
A= $expected_audienceB= $self->audience
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 26 | ▶ | my @audiences = ref $audience eq 'ARRAY' ? @$audience : ($audience); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 26 | ▶ | any { $_ eq $expected_audience } @audiences | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 55 | 26 | ▶ | "OIDC: unexpected audience, expected '$expected_audience' but got " . join(', ', map { "'$_'" } @audiences) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 5 | ▶ | sub _validate_authorized_party ($self, $azp, $expected_authorized_party) { | ||||||||||||||||||
|
Subroutine
_validate_authorized_party: called CC=5 SCAR=16.1
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 5 | ▶ | if (defined $expected_authorized_party) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 63 | 3 | ▶ | defined $azp | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'azp' claim is missing"); | ||||||||||||||||||||
| 65 | 2 | ▶ | $azp eq $expected_authorized_party | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 67 | "OIDC: unexpected authorized party, expected '$expected_authorized_party' but got '$azp'" | ||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | elsif (defined $azp) { | ||||||||||||||||||||
| 71 | 1 | OIDC::Client::Error::TokenValidation->throw("OIDC: unexpected 'azp' claim"); | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 3 | ▶ | sub _validate_subject ($self, $subject, $expected_subject) { | ||||||||||||||||||
|
Subroutine
_validate_subject: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | ▶ | defined $subject | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'sub' claim is missing"); | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | 2 | ▶ | $subject eq $expected_subject | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 82 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 83 | "OIDC: unexpected subject, expected '$expected_subject' but got '$subject'" | ||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 4 | ▶ | sub _validate_nonce ($self, $nonce, $expected_nonce) { | ||||||||||||||||||
|
Subroutine
_validate_nonce: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 4 | ▶ | defined $nonce | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'nonce' claim is missing"); | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 3 | ▶ | $nonce eq $expected_nonce | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 93 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 94 | "OIDC: unexpected nonce, expected '$expected_nonce' but got '$nonce'" | ||||||||||||||||||||
| 95 | ); | ||||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 3 | ▶ | sub _validate_age ($self, $issued_at, $max_token_age) { | ||||||||||||||||||
|
Subroutine
_validate_age: called CC=4 SCAR=14.5
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 3 | ▶ | defined $issued_at | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | or OIDC::Client::Error::TokenValidation->throw("OIDC: 'iat' claim is missing"); | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 3 | ▶ | $issued_at >= time - ($self->jwt_decoding_options->{leeway} // 0) - $max_token_age | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->jwt_decoding_options->{"leeway"} // 0
MC/DC0%0/1
$self->jwt_decoding_options->{"leeway"} // 0
$self->jwt_decoding_options->{"leeway"}
Truth table50%1/2
A
A= $self->jwt_decoding_options->{"leeway"}
| |||||||||||||||||||||
| 105 | or OIDC::Client::Error::TokenValidation->throw( | ||||||||||||||||||||
| 106 | "OIDC: the token is too old" | ||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 5 | 1; | |||||||||||||||||||