public function encode(array $payload, array $header = [])
    {
        $header = ['typ' => 'JWT', 'alg' => $this->algo] + $header;

        $this->validateKid($header);

        if (!isset($payload['iat']) && !isset($payload['exp'])) {
            $payload['exp'] = ($this->timestamp ?: \time()) + $this->maxAge;
        }

        $header    = $this->urlSafeEncode($header);
        $payload   = $this->urlSafeEncode($payload);
        $signature = $this->urlSafeEncode($this->sign($header . '.' . $payload));

        return $header . '.' . $payload . '.' . $signature;
    }
public function encode(array $payload, array $header = [])
    {
        $header = ['typ' => 'JWT', 'alg' => $this->algo] + $header;

        $this->validateKid($header);

        if (!isset($payload['iat']) && !isset($payload['exp'])) {
            $payload['exp'] = ($this->timestamp ?: \time()) + $this->maxAge;
        }

        $header    = $this->urlSafeEncode($header);
        $payload   = $this->urlSafeEncode($payload);
        $signature = $this->urlSafeEncode($this->sign($header . '.' . $payload));

        return $header . '.' . $payload . '.' . $signature;
    }
public function encode ( array $ payload , array $ header = [ ] ) { $ header = [ 'typ' => 'JWT' , 'alg' => $ this -> algo ] + $ header ; $ this -> validateKid ( $ header ) ; if ( ! isset ( $ payload [ 'iat' ] ) && ! isset ( $ payload [ 'exp' ] ) ) { $ payload [ 'exp' ] = ( $ this -> timestamp ? : \ time ( ) ) + $ this -> maxAge ; } $ header = $ this -> urlSafeEncode ( $ header ) ; $ payload = $ this -> urlSafeEncode ( $ payload ) ; $ signature = $ this -> urlSafeEncode ( $ this -> sign ( $ header . '.' . $ payload ) ) ; return $ header . '.' . $ payload . '.' . $ signature ; }
Encode payload as JWT token.

@param array $payload
@param array $header  Extra header (if any) to append.

@return string URL safe JWT token.
Encode payload as JWT token .