Beispiel #1
0
 /**
  * @param object|array $payload   PHP object or array
  * @param string       $key       The secret key
  * @param string       $kid       The key id
  * @param string       $algorithm The signing algorithm
  *
  * @return string A JWT
  */
 public static function encode($payload, $key, $kid = null, $algorithm = 'HS256')
 {
     $header = array('typ' => 'JWT', 'alg' => $algorithm, 'kid' => $kid);
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signingInput = implode('.', $segments);
     $signature = JWT::sign($signingInput, $key, $algorithm);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }