XMF Cookbook
  • Introduction
  • XMF Cookbook
  • Basic Ingredients
    • Namespaces
    • Autoloading
    • Debugging
    • Forward Compatibility
  • Recipes
    • Introducing Module Helpers
    • Using the Permission Helper
      • Checking Permissions
      • Managing Item Permissions
    • Using the Session Helper
    • Using JSON Web Tokens
    • Altering Database Tables
    • Migrating a Module's Database
    • Loading Initial Data
    • Module Admin Pages
      • Hide and Seek with Icons
      • Standard Admin Pages
    • Manage Metadata
    • Highlighting Content
  • Reference
    • Assert
      • Assertions
    • Database
      • Migrate
      • TableLoad
      • Tables
        • Getting Started
        • Table Operations
        • Working with Columns
        • Working with Indexes
        • Changing Table Data
        • Interacting with the Work Queue
        • Error Info and Debugging
    • Debug
    • FilterInput
    • Highlighter
    • IPAddress
    • Jwt
      • JsonWebToken
      • KeyFactory
      • TokenFactory
      • TokenReader
    • Key
      • ArrayStorage
      • Basic
      • FileStorage
      • KeyAbstract
      • StorageInterface
    • Language
    • Metagen
      • Extracting Data
      • Applying Data
    • Module
      • Admin
      • Helper
      • Helper
        • AbstractHelper
        • Cache
        • GenericHelper
        • Permission
        • Session
    • ProxyCheck
    • Random
    • Request
    • StopWords
    • Uuid
    • Yaml
  • Credits
  • License:
  • Table of Content
Powered by GitBook
On this page
  • new JsonWebToken($key, $algorithm)
  • setAlgorithm($algorithm)
  • decode($jwtString, $assertClaims)
  • create($payload, $expirationOffset)
  1. Reference
  2. Jwt

JsonWebToken

PreviousJwtNextKeyFactory

Last updated 6 years ago

The Xmf\Jwt\JsonWebToken class is used to create and decode JSON Web Tokens. A full description and specification of JSON Web Tokens can be found in .

new JsonWebToken($key, $algorithm)

Instantiates a new JsonWebToken object, using a object $key, using the specified $algorithm for signing and verifying. An invalid algorithm will throw \DomainException.

The default $algorithm is 'HS256', and the currently supplied and classes are locked to it. HS256 uses HMAC with SHA256 for signing and verifying.

setAlgorithm($algorithm)

Change the algorithm used for signing/verifying the token. An invalid algorithm will throw \DomainException.

decode($jwtString, $assertClaims)

Decode a JWT string $jwtString, validating signature and well defined registered claims, and optionally validate against a list of supplied claims in the $assertClaims.

Claims such as 'exp', expiration time, are automatically enforced. Application specific public or claims to be verified by specifying the required claims in $assertClaims array.

An example array could look like this: array('aud' => 'myscript');

If no application claims are to be validated, an empty array (the default) should be specified in $assertClaims.

Returns the payload of the decoded token as a stdClass object, or false if the token was invalid.

create($payload, $expirationOffset)

Create a signed token string for the array of claims specified in $payload. The integer $expirationOffset parameter can be used to specify an expiration time as the number of seconds from now that the token will expire. If specified, this will be added as an 'exp' claim to the payload.

Returns a string of the signed token with the specified payload.

RFC7519
Xmf\Key\KeyAbstract
TokenFactory
TokenReader