You are here

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

Sets the public key used to verify signatures for an asymmetric algorithm.

This key is only used when an asymmetric algorithm is selected. Currently supported asymmetric algorithms are:

  • RS256

Parameters

string $public_key: A PEM encoded public key.

Return value

mixed Function does some validation of the key. Returns TRUE on success.

Overrides JwtTranscoderInterface::setPublicKey

1 call to JwtTranscoder::setPublicKey()
JwtTranscoder::__construct in src/Transcoder/JwtTranscoder.php
Constructs a new JwtTranscoder.

File

src/Transcoder/JwtTranscoder.php, line 165

Class

JwtTranscoder
Class JwtTranscoder.

Namespace

Drupal\jwt\Transcoder

Code

public function setPublicKey($public_key) {
  $key_context = openssl_pkey_get_public($public_key);
  if ($key_context === FALSE) {
    return FALSE;
  }
  $key_details = openssl_pkey_get_details($key_context);
  if ($key_details === FALSE || $key_details['type'] != OPENSSL_KEYTYPE_RSA) {
    return FALSE;
  }
  $this->publicKey = $public_key;
  return TRUE;
}