php-jwt
php-jwt copied to clipboard
Question about Payload
If possible insert into payload sub array?
Example: "user": { "avatar": "https:/gravatar.com/avatar/abc123", "name": "xxx", "email": "xxx@xxx }, "aud": "zzzz", "iss": "zzzzz"
That would be very useful to add additional data to the token
As far as I see in the RFC-7519, its a valid request.
Sorry about the very late reply.
I see this usage is already available. An example code would be the following:
<?php
// composer require firebase/php-jwt
require __DIR__ . '/vendor/autoload.php';
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
$key = 'example_key';
$payload = [
'iss' => 'http://example.org',
'user' => [
'name' => 'http://example.org'
],
'aud' => 'http://example.com',
'iat' => 1356999524,
'nbf' => 1357000000
];
/**
* IMPORTANT:
* You must specify supported algorithms for your application. See
* https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40
* for a list of spec-compliant algorithms.
*/
$jwt = JWT::encode($payload, $key, 'HS256');
$decoded = JWT::decode($jwt, new Key($key, 'HS256'));
print_r($decoded);
// Pass a stdClass in as the third parameter to get the decoded header values
$headers = new stdClass();
$decoded = JWT::decode($jwt, new Key($key, 'HS256'), $headers);
print_r($headers);
Thank you for asking. Closing this thread.