You are here

public function JwtTranscoder::encode in JSON Web Token Authentication (JWT) 8

Same name and namespace in other branches
  1. 8.0 src/Transcoder/JwtTranscoder.php \Drupal\jwt\Transcoder\JwtTranscoder::encode()

Encodes a JsonWebToken.

Parameters

\Drupal\jwt\JsonWebToken\JsonWebTokenInterface $jwt: A JWT.

Return value

string The encoded JWT.

Overrides JwtTranscoderInterface::encode

File

src/Transcoder/JwtTranscoder.php, line 197

Class

JwtTranscoder
Class JwtTranscoder.

Namespace

Drupal\jwt\Transcoder

Code

public function encode(JsonWebTokenInterface $jwt) {
  $key = $this
    ->getKey('encode');

  // Refuse to encode if we don't have a key yet.
  if ($key === NULL) {
    return FALSE;
  }
  $encoded = $this->transcoder
    ->encode($jwt
    ->getPayload(), $key, $this->algorithm);
  return $encoded;
}