当前位置: 首页>>代码示例>>PHP>>正文


PHP JWT::sign方法代码示例

本文整理汇总了PHP中JWT::sign方法的典型用法代码示例。如果您正苦于以下问题:PHP JWT::sign方法的具体用法?PHP JWT::sign怎么用?PHP JWT::sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JWT的用法示例。


在下文中一共展示了JWT::sign方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: encode

 /**
  * @param object|array $payload PHP object or array
  * @param string       $key     The secret key
  * @param string       $algo    The signing algorithm
  *
  * @return string A JWT
  */
 public static function encode($payload, $key, $algo = 'HS256')
 {
     $header = array('typ' => 'jwt', 'alg' => $algo);
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $algo);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
开发者ID:lbbniu,项目名称:php-jwt,代码行数:18,代码来源:JWT.php

示例2: encode

 /**
  * @param object|array $payload PHP object or array
  * @param string       $key     The secret key
  * @param string       $algo    The signing algorithm
  *
  * @return string A JWT
  */
 public static function encode($payload, $key, $type, $algo = 'HS256')
 {
     $header = array('typ' => 'JWT', 'alg' => $algo);
     $segments = array();
     $tmp_str = implode(',', $payload);
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     if ($type) {
         $segments[] = JWT::urlsafeB64Encode_parse(JWT::jsonEncode($payload));
     } else {
         $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     }
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $algo);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
开发者ID:laiello,项目名称:xyz-php-sample,代码行数:23,代码来源:jwt.php

示例3: verifySignature

 private static function verifySignature($signature, $input, $key, $algo)
 {
     switch ($algo) {
         case 'HS256':
         case 'HS384':
         case 'HS512':
             return JWT::sign($input, $key, $algo) === $signature;
         case 'RS256':
             return (bool) openssl_verify($input, $signature, $key, OPENSSL_ALGO_SHA256);
         case 'RS384':
             return (bool) openssl_verify($input, $signature, $key, OPENSSL_ALGO_SHA384);
         case 'RS512':
             return (bool) openssl_verify($input, $signature, $key, OPENSSL_ALGO_SHA512);
         default:
             throw new Exception("Unsupported or invalid signing algorithm.");
     }
 }
开发者ID:aodkrisda,项目名称:phprest,代码行数:17,代码来源:JWT.php

示例4: encode

 public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null)
 {
     $header = array('typ' => 'JWT', 'alg' => $alg);
     if ($keyId !== null) {
         $header['kid'] = $keyId;
     }
     if (isset($head) && is_array($head)) {
         $header = array_merge($head, $header);
     }
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $alg);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
开发者ID:inspurhua,项目名称:myjwt,代码行数:17,代码来源:JWT.php

示例5: encode

 /**
  * Converts and signs a PHP object or array into a JWT string.
  *
  * @param object|array $payload PHP object or array
  * @param string       $key     The secret key
  * @param string       $alg     The signing algorithm. Supported
  *                              algorithms are 'HS256', 'HS384' and 'HS512'
  * @param array        $head    An array with header elements to attach
  * @param array        $options Extra options (audience, issuer, jwtid, subject)
  *
  * @return string      A signed JWT
  * @uses jsonEncode
  * @uses urlsafeB64Encode
  */
 public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null, $options = array())
 {
     $header = array('typ' => 'JWT', 'alg' => $alg);
     if ($keyId !== null) {
         $header['kid'] = $keyId;
     }
     if (isset($head) && is_array($head)) {
         $header = array_merge($head, $header);
     }
     if (isset($options['audience']) && (is_string($options['audience']) || is_array($options['audience']))) {
         if (is_array($payload)) {
             $payload['aud'] = is_array($options['audience']) ? $options['audience'] : array($options['audience']);
         } else {
             if (is_object($payload)) {
                 $payload->aud = is_array($options['audience']) ? $options['audience'] : array($options['audience']);
             }
         }
     }
     if (isset($options['issuer']) && is_string($options['issuer'])) {
         if (is_array($payload)) {
             $payload['iss'] = $options['issuer'];
         } else {
             if (is_object($payload)) {
                 $payload->iss = $options['issuer'];
             }
         }
     }
     if (isset($options['subject']) && is_string($options['subject'])) {
         if (is_array($payload)) {
             $payload['sub'] = $options['subject'];
         } else {
             if (is_object($payload)) {
                 $payload->sub = $options['subject'];
             }
         }
     }
     if (isset($options['jwtid']) && is_string($options['jwtid'])) {
         if (is_array($payload)) {
             $payload['jti'] = $options['jwtid'];
         } else {
             if (is_object($payload)) {
                 $payload->jti = $options['jwtid'];
             }
         }
     }
     $segments = array();
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($header));
     $segments[] = JWT::urlsafeB64Encode(JWT::jsonEncode($payload));
     $signing_input = implode('.', $segments);
     $signature = JWT::sign($signing_input, $key, $alg);
     $segments[] = JWT::urlsafeB64Encode($signature);
     return implode('.', $segments);
 }
开发者ID:TATDK,项目名称:php-jwt,代码行数:67,代码来源:JWT.php

示例6: gerar_token

 public static function gerar_token()
 {
     require_once PROJECT_ADDRESS . "/lib/util/JWT.php";
     $jwt = new JWT();
     $jwt->setHeader();
     $jwt->setPayload(UsuarioController::$usuario->getJson("email,codigo"));
     $jwt->sign(jwt_secret_key());
     self::$sessao->setToken($jwt->getToken());
 }
开发者ID:DaniloEpic,项目名称:slast,代码行数:9,代码来源:SessaoController.php


注:本文中的JWT::sign方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。