jwt icon indicating copy to clipboard operation
jwt copied to clipboard

Improve token builder interface

Open lcobucci opened this issue 10 years ago • 2 comments

The Lcobucci\JWT\Builder interface is not so fluent as it could be...

I'm thinking that this would be better:

class Builder
{
    public function withId(string $id, bool $addHeader = false): Builder; // replace 'jti'
    public function relatedTo(string $subject, bool $addHeader = false): Builder; // replace 'sub'
    public function issuedBy(string $issuer, bool $addHeader = false): Builder; // replace 'iss'
    public function canOnlyBeUsedBy(string $audience, bool $addHeader = false): Builder; // append 'aud'

    public function canOnlyBeUsedAfter(int $notBefore, bool $addHeader = false): Builder; // replace 'nbf'
    public function expiresAt(int $expiration, bool $addHeader = false): Builder; // replace 'exp'
    public function issuedAt(int $issuedAt, bool $addHeader = false): Builder; // replace 'iat'

    public function withHeader(string $name, $value): Builder;
    public function with(string $name, $value): Builder;

    public function sign(Signer $signer, Key $key): Builder;
    public function unsign(): Builder;

    public function getToken(): Token;
}

Any suggestions?

lcobucci avatar Aug 14 '16 00:08 lcobucci

I really like this (I'm using your library in league/oauth2-server). 👍 from me.

alexbilbie avatar Aug 21 '16 12:08 alexbilbie

Working on it 👍

MarijnKoesen avatar Sep 30 '16 19:09 MarijnKoesen