File Coverage

blib/lib/OIDC/Client/Identity.pm
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 5 5 100.0
pod 1 1 100.0
total 27 27 100.0


line stmt bran cond sub pod time code
1             package OIDC::Client::Identity;
2 4     4   564053 use utf8;
  4         421  
  4         33  
3 4     4   922 use Moose;
  4         513207  
  4         63  
4 4     4   40394 use MooseX::Params::Validate;
  4         117012  
  4         73  
5 4     4   3292 use namespace::autoclean;
  4         12287  
  4         41  
6              
7             has 'subject' => (
8             is => 'ro',
9             isa => 'Str',
10             required => 1,
11             );
12              
13             has 'claims' => (
14             is => 'ro',
15             isa => 'HashRef',
16             required => 1,
17             );
18              
19             has 'token' => (
20             is => 'ro',
21             isa => 'Str',
22             required => 1,
23             );
24              
25             has 'expires_at' => (
26             is => 'ro',
27             isa => 'Maybe[Int]',
28             required => 0,
29             );
30              
31             =encoding utf8
32              
33             =head1 NAME
34              
35             OIDC::Client::Identity - Identity class
36              
37             =head1 DESCRIPTION
38              
39             Class representing an identity
40              
41             =head1 ATTRIBUTES
42              
43             =head2 subject
44              
45             The subject identifier coming from the ID token. Required
46              
47             =head2 claims
48              
49             Hashref of claims coming from the ID token. Required
50              
51             =head2 token
52              
53             The string of the ID token. Required
54              
55             =head2 expires_at
56              
57             The expiration time of the identity (number of seconds since 1970-01-01T00:00:00Z)
58              
59             =head1 METHODS
60              
61             =head2 has_expired( $leeway )
62              
63             my $has_expired = $identity->has_expired();
64              
65             Returns whether the identity has expired.
66              
67             Returns undef if the C<expires_at> attribute is not defined.
68              
69             The list parameters are:
70              
71             =over 2
72              
73             =item leeway
74              
75             Number of seconds of leeway for the identity to be considered expired before it actually is.
76              
77             =back
78              
79             =cut
80              
81             sub has_expired {
82 7     7 1 118 my $self = shift;
83 7         42 my ($leeway) = pos_validated_list(\@_, { isa => 'Maybe[Int]', optional => 1 });
84 7   100     1527 $leeway //= 0;
85              
86 7 100       268 return unless defined $self->expires_at;
87              
88 5         133 return ( $self->expires_at - $leeway ) < time;
89             }
90              
91             __PACKAGE__->meta->make_immutable;
92              
93             1;