Namshi\JOSE\JWS::load PHP Метод

load() публичный статический Метод

Creates an instance of a JWS from a JWT.
public static load ( string $jwsTokenString, boolean $allowUnsecure = false, Namshi\JOSE\Base64\Encoder $encoder = null, string $encryptionEngine = 'OpenSSL' ) : JWS
$jwsTokenString string
$allowUnsecure boolean
$encoder Namshi\JOSE\Base64\Encoder
$encryptionEngine string
Результат JWS
    public static function load($jwsTokenString, $allowUnsecure = false, Encoder $encoder = null, $encryptionEngine = 'OpenSSL')
    {
        if ($encoder === null) {
            $encoder = strpbrk($jwsTokenString, '+/=') ? new Base64Encoder() : new Base64UrlSafeEncoder();
        }
        $parts = explode('.', $jwsTokenString);
        if (count($parts) === 3) {
            $header = json_decode($encoder->decode($parts[0]), true);
            $payload = json_decode($encoder->decode($parts[1]), true);
            if (is_array($header) && is_array($payload)) {
                if (strtolower($header['alg']) === 'none' && !$allowUnsecure) {
                    throw new InvalidArgumentException(sprintf('The token "%s" cannot be validated in a secure context, as it uses the unallowed "none" algorithm', $jwsTokenString));
                }
                $jws = new static($header, $encryptionEngine);
                $jws->setEncoder($encoder)->setHeader($header)->setPayload($payload)->setEncodedSignature($parts[2]);
                return $jws;
            }
        }
        throw new InvalidArgumentException(sprintf('The token "%s" is an invalid JWS', $jwsTokenString));
    }

Usage Example

Пример #1
0
 /**
  * Decode a JSON Web Token.
  *
  * @param  string  $token
  *
  * @throws \Tymon\JWTAuth\Exceptions\JWTException
  *
  * @return array
  */
 public function decode($token)
 {
     try {
         // Let's never allow insecure tokens
         $jws = $this->jws->load($token, false);
     } catch (InvalidArgumentException $e) {
         throw new TokenInvalidException('Could not decode token: ' . $e->getMessage());
     }
     if (!$jws->verify($this->getVerificationKey(), $this->getAlgo())) {
         throw new TokenInvalidException('Token Signature could not be verified.');
     }
     return (array) $jws->getPayload();
 }
All Usage Examples Of Namshi\JOSE\JWS::load