You are here

protected function JwtTranscoder::getKey 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::getKey()

Helper function to get the correct key based on operation.

Parameters

string $operation: The operation being performed. One of: encode, decode.

Return value

null|string Returns NULL if opteration is not found. Otherwise returns key.

2 calls to JwtTranscoder::getKey()
JwtTranscoder::decode in src/Transcoder/JwtTranscoder.php
Gets a validated JsonWebToken from an encoded JWT.
JwtTranscoder::encode in src/Transcoder/JwtTranscoder.php
Encodes a JsonWebToken.

File

src/Transcoder/JwtTranscoder.php, line 216

Class

JwtTranscoder
Class JwtTranscoder.

Namespace

Drupal\jwt\Transcoder

Code

protected function getKey($operation) {
  if ($this->algorithmType == 'jwt_hs') {
    return $this->secret;
  }
  elseif ($this->algorithmType == 'jwt_rs') {
    if ($operation == 'encode') {
      return $this->privateKey;
    }
    elseif ($operation == 'decode') {
      return $this->publicKey;
    }
  }
  return NULL;
}