We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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


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


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



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