Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add claims() function to token interface #1044

Closed
christopherboisvert opened this issue Jan 27, 2024 · 4 comments
Closed

Add claims() function to token interface #1044

christopherboisvert opened this issue Jan 27, 2024 · 4 comments

Comments

@christopherboisvert
Copy link

christopherboisvert commented Jan 27, 2024

Hi ! Whenever I open my code where I get the claims out of the token. PHP can't find the claims function in the interface and mark it as not existing. I suggest adding it in Token.php interface so the error won't be shown.

Example of modified Token.php :

declare(strict_types=1);

namespace Lcobucci\JWT;

use DateTimeInterface;
use Lcobucci\JWT\Token\DataSet;

interface Token
{
    /**
     * Returns the token headers
     */
    public function headers(): DataSet;

    /**
     * Returns the token claims
     */
    public function claims(): DataSet;

    /**
     * Returns if the token is allowed to be used by the audience
     *
     * @param non-empty-string $audience
     */
    public function isPermittedFor(string $audience): bool;

    /**
     * Returns if the token has the given id
     *
     * @param non-empty-string $id
     */
    public function isIdentifiedBy(string $id): bool;

    /**
     * Returns if the token has the given subject
     *
     * @param non-empty-string $subject
     */
    public function isRelatedTo(string $subject): bool;

    /**
     * Returns if the token was issued by any of given issuers
     *
     * @param non-empty-string ...$issuers
     */
    public function hasBeenIssuedBy(string ...$issuers): bool;

    /**
     * Returns if the token was issued before of given time
     */
    public function hasBeenIssuedBefore(DateTimeInterface $now): bool;

    /**
     * Returns if the token minimum time is before than given time
     */
    public function isMinimumTimeBefore(DateTimeInterface $now): bool;

    /**
     * Returns if the token is expired
     */
    public function isExpired(DateTimeInterface $now): bool;

    /**
     * Returns an encoded representation of the token
     *
     * @return non-empty-string
     */
    public function toString(): string;
}
@Ocramius
Copy link
Collaborator

Note: adding methods to an interface is a major BC break, so we'd need a new interface for that

@Slamdunk
Copy link
Collaborator

Duplicate of #611 and #186

@Slamdunk Slamdunk closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2024
@Slamdunk
Copy link
Collaborator

I suggest you to use the JwtFacade (https://lcobucci-jwt.readthedocs.io/en/stable/quick-start/) that already return an UnencryptedToken with the claims() method declared.

@christopherboisvert
Copy link
Author

Hi ! Thanks for all the reference issues guys. I will look at the JwtFacade, I did not know this existed. I will implement that in all my projects hehe 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants