JSON Web TokenJSON Web Token
Home
Documentation
GitHub
  • English
  • 简体中文
Home
Documentation
GitHub
  • English
  • 简体中文
  • Introduction

    • Installation
    • Supported Algorithms
  • Usage

    • Configuration
    • Issuing tokens
    • Parsing tokens
    • Validating tokens
  • Guides

    • Extending the library

Parsing tokens

To parse a token you must create a new parser and ask it to parse a string:

use Token\JWT\Parser;
use Token\JWT\Encoding\JoseEncoder;

$parser = new Parser(new JoseEncoder());

$token = $parser->parse(
    'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.'
    . 'eyJzdWIiOiIxMjM0NTY3ODkwIn0.'
    . '2gSBz9EOsQRN9I-3iSxJoFt7NtgV6Rm0IL6a8CAwl3Q'
);

var_dump($token->headers()); // Retrieves the token headers
var_dump($token->claims()); // Retrieves the token claims

Important In case of parsing errors the Parser will throw an exception of type InvalidArgumentException.

Last Updated:: 4/15/25, 8:29 PM
Contributors: jundayw
Prev
Issuing tokens
Next
Validating tokens