We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon\Security\JWT\Builder : how to set a custom claim

I'm switching from the JWT library made by Lcobucci to the native one offered by Phalcon 4.1 I can't figure out how to define custom claims. I can set all the standard ones thanks to the public functions on the Builder class, but the setClaim function is a private one.

How can I define a custom claim?

see: https://github.com/phalcon/cphalcon/tree/master/phalcon/Security/JWT



618

As a workaround I created an object with all my claims, json_encoded it and set it as the jwt's subject



8.4k
Accepted
answer

it not documented yet

Phalcon\Security\JWT\Builder::setClaim() is a private method

you can extend the builder class and add a method to add claims

example:

<?php

use Phalcon\Security\JWT\Builder;

class MyBuilder extends Builder
{
    public function addClaim(string $name, $value): Builder
    {
        return $this->setClaim($name, $value);
    }
}
edited Dec '20

Added JWT (JSON Web Tokens) support under Phalcon\Security\JWT . to set a callback which pre-formats actions to custom pattern #14819; Added new PDO Optionally the statements can be executed from the builder itself using the

TargetPayandBenefits Login