line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OIDC::Lite::Util::JWT; |
2
|
3
|
|
|
3
|
|
51329
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
87
|
|
3
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
102
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
15
|
use JSON::XS qw/decode_json encode_json/; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
215
|
|
6
|
3
|
|
|
3
|
|
14
|
use MIME::Base64 qw/encode_base64url decode_base64url/; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
181
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
3
|
|
|
|
|
1024
|
JWT_ALG_LEN => 2, |
10
|
|
|
|
|
|
|
JWT_BITS_LEN => 3, |
11
|
|
|
|
|
|
|
JWT_ALG_NONE => q{none}, |
12
|
|
|
|
|
|
|
JWT_ALG_HMAC => q{HS}, |
13
|
|
|
|
|
|
|
JWT_ALG_RSA => q{RS}, |
14
|
|
|
|
|
|
|
JWT_ALG_ECDSA => q{ES}, |
15
|
3
|
|
|
3
|
|
16
|
}; |
|
3
|
|
|
|
|
7
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
OIDC::Lite::Util::JWT - JSON Web Token |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
TBD |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
JSON Web Token utility class. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 METHODS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 header( $jwt ) |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Returns hash reference of JWT Header. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $jwt = q{...}: |
36
|
|
|
|
|
|
|
my $header = OIDC::Lite::Util::JWT::header($jwt); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub header { |
41
|
20
|
|
|
20
|
1
|
9222
|
my ($jwt) = @_; |
42
|
20
|
|
|
|
|
96
|
my $segments = [split(/\./, $jwt)]; |
43
|
20
|
100
|
100
|
|
|
115
|
return unless (@$segments == 2 or @$segments == 3); |
44
|
|
|
|
|
|
|
|
45
|
19
|
|
|
|
|
44
|
my ($header_segment, $payload_segment, $crypt_segment) = @$segments; |
46
|
19
|
|
|
|
|
21
|
my $header; |
47
|
19
|
|
|
|
|
36
|
eval { |
48
|
19
|
|
|
|
|
85
|
$header = decode_json(decode_base64url($header_segment)); |
49
|
|
|
|
|
|
|
}; |
50
|
19
|
100
|
|
|
|
366
|
return if $@; |
51
|
16
|
|
|
|
|
65
|
return $header; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 payload( $jwt ) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Returns hash reference of JWT Payload. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $jwt = q{...}: |
59
|
|
|
|
|
|
|
my $payload = OIDC::Lite::Util::JWT::payload($jwt); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub payload { |
64
|
21
|
|
|
21
|
1
|
7687
|
my ($jwt) = @_; |
65
|
21
|
|
|
|
|
90
|
my $segments = [split(/\./, $jwt)]; |
66
|
21
|
100
|
100
|
|
|
117
|
return unless (@$segments == 2 or @$segments == 3); |
67
|
|
|
|
|
|
|
|
68
|
20
|
|
|
|
|
39
|
my ($header_segment, $payload_segment, $crypt_segment) = @$segments; |
69
|
20
|
|
|
|
|
32
|
my $payload; |
70
|
20
|
|
|
|
|
28
|
eval { |
71
|
20
|
|
|
|
|
70
|
$payload = decode_json(decode_base64url($payload_segment)); |
72
|
|
|
|
|
|
|
}; |
73
|
20
|
100
|
|
|
|
302
|
return if $@; |
74
|
17
|
|
|
|
|
72
|
return $payload; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Ryo Ito Eritou.06@gmail.comE |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (C) 2012 by Ryo Ito |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 LICENSE |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
88
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
89
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |