line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OIDC::Lite::Util::JWT; |
2
|
3
|
|
|
3
|
|
32315
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
103
|
|
3
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
105
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
12
|
use JSON::XS qw/decode_json encode_json/; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
187
|
|
6
|
3
|
|
|
3
|
|
14
|
use MIME::Base64 qw/encode_base64url decode_base64url/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
228
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use constant { |
9
|
3
|
|
|
|
|
913
|
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
|
|
18
|
}; |
|
3
|
|
|
|
|
5
|
|
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
|
5501
|
my ($jwt) = @_; |
42
|
20
|
|
|
|
|
80
|
my $segments = [split(/\./, $jwt)]; |
43
|
20
|
100
|
100
|
|
|
103
|
return unless (@$segments == 2 or @$segments == 3); |
44
|
|
|
|
|
|
|
|
45
|
19
|
|
|
|
|
31
|
my ($header_segment, $payload_segment, $crypt_segment) = @$segments; |
46
|
19
|
|
|
|
|
16
|
my $header; |
47
|
19
|
|
|
|
|
27
|
eval { |
48
|
19
|
|
|
|
|
63
|
$header = decode_json(decode_base64url($header_segment)); |
49
|
|
|
|
|
|
|
}; |
50
|
19
|
100
|
|
|
|
308
|
return if $@; |
51
|
16
|
|
|
|
|
50
|
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
|
5321
|
my ($jwt) = @_; |
65
|
21
|
|
|
|
|
82
|
my $segments = [split(/\./, $jwt)]; |
66
|
21
|
100
|
100
|
|
|
100
|
return unless (@$segments == 2 or @$segments == 3); |
67
|
|
|
|
|
|
|
|
68
|
20
|
|
|
|
|
32
|
my ($header_segment, $payload_segment, $crypt_segment) = @$segments; |
69
|
20
|
|
|
|
|
26
|
my $payload; |
70
|
20
|
|
|
|
|
29
|
eval { |
71
|
20
|
|
|
|
|
48
|
$payload = decode_json(decode_base64url($payload_segment)); |
72
|
|
|
|
|
|
|
}; |
73
|
20
|
100
|
|
|
|
279
|
return if $@; |
74
|
17
|
|
|
|
|
60
|
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; |