You are here

public function JwtTranscoder::decode 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::decode()

Gets a validated JsonWebToken from an encoded JWT.

Parameters

string $jwt: The encoded JWT.

Return value

\Drupal\jwt\JsonWebToken\JsonWebTokenInterface Validated JWT.

Throws

\Drupal\jwt\Transcoder\JwtDecodeException

Overrides JwtTranscoderInterface::decode

File

src/Transcoder/JwtTranscoder.php, line 182

Class

JwtTranscoder
Class JwtTranscoder.

Namespace

Drupal\jwt\Transcoder

Code

public function decode($jwt) {
  $key = $this
    ->getKey('decode');
  $algorithms = [
    $this->algorithm,
  ];
  try {
    $token = $this->transcoder
      ->decode($jwt, $key, $algorithms);
  } catch (\Exception $e) {
    throw JwtDecodeException::newFromException($e);
  }
  return new JsonWebToken($token);
}