Hi pheonix,

Unless I'm mistaken, if you have used a private key to sign the token, the decode_token function will fail if you use the wrong public key.

It might help if you could post the code which you have written so we can see how you are encoding and decoding the tokens.

Heres a quick test I ran which shows that if you are using the 'RS256' algorithm the decoding will fail without the correct key:

#! /usr/bin/env perl use strict; use warnings; use autodie; use Test::More; use Data::Dumper; use File::Slurp; use Crypt::JWT qw(encode_jwt decode_jwt); my $private_key = read_file('throwaway.pem'); my $public_key = read_file('throwaway.pem.pub'); my $wrong_public_key = read_file('fake_key.pem.pub'); my $payload = { just => 'another', perl => 'hacker' }; my $token = encode_jwt( payload => $payload, key => \$private_key, alg => 'RS256' ); ok( decode_jwt( token => $token, key => \$public_key ) ); ok( decode_jwt( token => $token, key => \$wrong_public_key )); done_testing(); $ ./test_jwt.pl ok 1 JWS: decode failed at ./test_jwt.pl line 26. # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 255 just after 1.

Hope this helps,

Jim


In reply to Re: Validating JWT by jimpudar
in thread Validating JWT by phoenix.fire

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.