JWTs

Overview

Issue, validate, refresh, revoke, and list AAM JWTs for a user. Select the subject with AAM::api()->jwts($access_level, $settings). Omit $access_level to use the current user or visitor.

PHP class: AAM_Framework_Service_Jwts.

Method reference

Method Purpose
get_tokens() List registered JWTs.
tokens() Alias of get_tokens().
get_token_by($search, $claim = null) Find a registered JWT.
token_by($search, $claim = null) Alias of get_token_by().
issue(array $claims = [], array $settings = []) Issue a JWT.
revoke($token) Revoke a registered JWT.
refresh($token) Refresh a refreshable JWT.
validate($token) Validate a JWT.
reset() Remove one rule or all rules for this level.

Return values vary by method. Rule updates usually return bool; reads can return a value, null, or an array. Errors follow the service’s error_handling setting and may produce WP_Error.

Accepted identifiers

This service is bound to a user access level; it has no separate resource identifier. Pass the JWT string to validate($token), refresh($token), or revoke($token). get_token_by($search, $claim) searches by token when $claim is omitted, or by a claim value when a claim name is supplied. issue() takes claim and settings arrays.

Example

$tokens = AAM::api()->jwts('user:42');
$issued = $tokens->issue([], ['ttl' => 3600, 'revocable' => true]);

The first argument to issue() is a claims array; the second contains token settings. This issues a revocable token for user 42 with a one-hour lifetime, and $issued contains token details.

Developer notes

Behavior and parameters