.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.29) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "JSON::WebToken 3pm" .TH JSON::WebToken 3pm "2016-03-21" "perl v5.22.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" JSON::WebToken \- JSON Web Token (JWT) implementation .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& use Test::More; \& use JSON; \& use JSON::WebToken; \& \& my $claims = { \& iss => \*(Aqjoe\*(Aq, \& exp => 1300819380, \& \*(Aqhttp://example.com/is_root\*(Aq => JSON::true, \& }; \& my $secret = \*(Aqsecret\*(Aq; \& \& my $jwt = encode_jwt $claims, $secret; \& my $got = decode_jwt $jwt, $secret; \& is_deeply $got, $claims; \& \& done_testing; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" JSON::WebToken is \s-1JSON\s0 Web Token (\s-1JWT\s0) implementation for Perl .PP \&\fB\s-1THIS MODULE IS ALPHA LEVEL INTERFACE.\s0\fR .SH "METHODS" .IX Header "METHODS" .ie n .SS "encode($claims [, $secret, $algorithm, $extra_headers ]) : String" .el .SS "encode($claims [, \f(CW$secret\fP, \f(CW$algorithm\fP, \f(CW$extra_headers\fP ]) : String" .IX Subsection "encode($claims [, $secret, $algorithm, $extra_headers ]) : String" This method is encoding \s-1JWT\s0 from hash reference. .PP .Vb 9 \& my $jwt = JSON::WebToken\->encode({ \& iss => \*(Aqjoe\*(Aq, \& exp => 1300819380, \& \*(Aqhttp://example.com/is_root\*(Aq => JSON::true, \& }, \*(Aqsecret\*(Aq); \& # $jwt = join \*(Aq.\*(Aq, \& # \*(AqeyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9\*(Aq, \& # \*(AqeyJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlLCJpc3MiOiJqb2UifQ\*(Aq \& # \*(Aq4ldFxjibgJGz_uaIRCIq89b5ipR\-sbI2Uq7B2WNEDs0\*(Aq .Ve .PP Default encryption algorithm is \f(CW\*(C`HS256\*(C'\fR. You can change algorithm as following: .PP .Vb 2 \& my $pricate_key_string = \*(Aq...\*(Aq; \& my $public_key_string = \*(Aq...\*(Aq; \& \& my $jwt = JSON::WebToken\->encode({ \& iss => \*(Aqjoe\*(Aq, \& exp => 1300819380, \& \*(Aqhttp://example.com/is_root\*(Aq => JSON::true, \& }, $pricate_key_string, \*(AqRS256\*(Aq); \& \& my $claims = JSON::WebToken\->decode($jwt, $public_key_string); .Ve .PP When you use \s-1RS256, RS384\s0 or \s-1RS512\s0 algorithm then, We need Crypt::OpenSSL::RSA. .PP If you want to create a \f(CW\*(C`Plaintext JWT\*(C'\fR, should be specify \f(CW\*(C`none\*(C'\fR for the algorithm. .PP .Vb 9 \& my $jwt = JSON::WebToken\->encode({ \& iss => \*(Aqjoe\*(Aq, \& exp => 1300819380, \& \*(Aqhttp://example.com/is_root\*(Aq => JSON::true, \& }, \*(Aq\*(Aq, \*(Aqnone\*(Aq); \& # $jwt = join \*(Aq.\*(Aq, \& # \*(AqeyJhbGciOiJub25lIiwidHlwIjoiSldUIn0\*(Aq, \& # \*(AqeyJleHAiOjEzMDA4MTkzODAsImh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlLCJpc3MiOiJqb2UifQ\*(Aq, \& # \*(Aq\*(Aq .Ve .ie n .SS "decode($jwt [, $secret, $verify_signature, $accepted_algorithms ]) : \s-1HASH\s0" .el .SS "decode($jwt [, \f(CW$secret\fP, \f(CW$verify_signature\fP, \f(CW$accepted_algorithms\fP ]) : \s-1HASH\s0" .IX Subsection "decode($jwt [, $secret, $verify_signature, $accepted_algorithms ]) : HASH" This method is decoding hash reference from \s-1JWT\s0 string. .PP .Vb 1 \& my $claims = JSON::WebToken\->decode($jwt, $secret, 1, ["RS256"]); .Ve .PP Any signing algorithm (except \*(L"none\*(R") is acceptable by default, so you should check it with \f(CW$accepted_algorithms\fR parameter. .ie n .SS "add_signing_algorithm($algorithm, $class)" .el .SS "add_signing_algorithm($algorithm, \f(CW$class\fP)" .IX Subsection "add_signing_algorithm($algorithm, $class)" This method is adding signing algorithm. .PP .Vb 2 \& # resolve JSON::WebToken::Crypt::MYALG \& JSON::WebToken\->add_signing_algorithm(\*(AqMYALGXXX\*(Aq => \*(AqMYALG\*(Aq); \& \& # resolve Some::Class::Algorithm \& JSON::WebToken\->add_signing_algorithm(\*(AqSOMEALGXXX\*(Aq => \*(Aq+Some::Class::Algorithm\*(Aq); .Ve .PP \&\s-1SEE ALSO \s0JSON::WebToken::Crypt::HMAC or JSON::WebToken::Crypt::RAS. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .ie n .SS "encode_jwt($claims [, $secret, $algorithm, $extra_headers ]) : String" .el .SS "encode_jwt($claims [, \f(CW$secret\fP, \f(CW$algorithm\fP, \f(CW$extra_headers\fP ]) : String" .IX Subsection "encode_jwt($claims [, $secret, $algorithm, $extra_headers ]) : String" Same as \f(CW\*(C`encode()\*(C'\fR method. .ie n .SS "decode_jwt($jwt [, $secret, $verify_signature, $accepted_algorithms ]) : Hash" .el .SS "decode_jwt($jwt [, \f(CW$secret\fP, \f(CW$verify_signature\fP, \f(CW$accepted_algorithms\fP ]) : Hash" .IX Subsection "decode_jwt($jwt [, $secret, $verify_signature, $accepted_algorithms ]) : Hash" Same as \f(CW\*(C`decode()\*(C'\fR method. .SH "ERROR CODES" .IX Header "ERROR CODES" JSON::WebToken::Exception will be thrown with following code. .SS "\s-1ERROR_JWT_INVALID_PARAMETER\s0" .IX Subsection "ERROR_JWT_INVALID_PARAMETER" When some method arguments are not valid. .SS "\s-1ERROR_JWT_MISSING_SECRET\s0" .IX Subsection "ERROR_JWT_MISSING_SECRET" When secret is required. (\f(CW\*(C`alg != "none"\*(C'\fR) .SS "\s-1ERROR_JWT_INVALID_SEGMENT_COUNT\s0" .IX Subsection "ERROR_JWT_INVALID_SEGMENT_COUNT" When \s-1JWT\s0 segment count is not between 2 and 4. .SS "\s-1ERROR_JWT_INVALID_SEGMENT_ENCODING\s0" .IX Subsection "ERROR_JWT_INVALID_SEGMENT_ENCODING" When each \s-1JWT\s0 segment is not encoded by base64url. .SS "\s-1ERROR_JWT_UNWANTED_SIGNATURE\s0" .IX Subsection "ERROR_JWT_UNWANTED_SIGNATURE" When \f(CW\*(C`alg == "none"\*(C'\fR but signature segment found. .SS "\s-1ERROR_JWT_INVALID_SIGNATURE\s0" .IX Subsection "ERROR_JWT_INVALID_SIGNATURE" When \s-1JWT\s0 signature is invalid. .SS "\s-1ERROR_JWT_NOT_SUPPORTED_SIGNING_ALGORITHM\s0" .IX Subsection "ERROR_JWT_NOT_SUPPORTED_SIGNING_ALGORITHM" When given signing algorithm is not supported. .SS "\s-1ERROR_JWT_UNACCEPTABLE_ALGORITHM\s0" .IX Subsection "ERROR_JWT_UNACCEPTABLE_ALGORITHM" When given signing algorithm is not included in acceptable_algorithms. .SH "AUTHOR" .IX Header "AUTHOR" xaicron .PP zentooo .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright 2012 \- xaicron .SH "LICENSE" .IX Header "LICENSE" This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO"