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


PHP JWT::encode方法代码示例

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


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

示例1: muestra

 public function muestra()
 {
     //$decoded =  JWT::decode($jwt, $this->clave, 'HS256');
     $clave = "beimarhuarachi";
     $user = array('nombre' => 'beimar', 'apellido' => 'huarachi');
     $jwt = JWT::encode($user, $clave, 'HS256');
     echo $jwt;
     echo "Login";
     $ahora = Carbon::now('America/La_Paz');
     $otra = Carbon::now('America/Halifax');
     $hoydia = Carbon::now();
     echo $ahora;
     echo "<br>";
     echo $hoydia;
     echo "<br>";
     echo $otra;
     echo "<br>";
     echo new Carbon('2015-12-12');
     $Y2K = Carbon::create(2000, 1, 1, 0, 0, 0);
     echo "<br>";
     echo $Y2K;
     echo "<br>";
     echo Carbon::parse('2015-02-12 12:00:12');
     //Es para obtener los datos de cualquier peticion(EL CLIENTE TIENE QUE ENVIAR LOS DATOS EN FORMATO JSON)
     //SI NOS ENVIA EN FORMATO DE FORMULARIO EL ACCESO SERIA DIRECTO
     //$entityBody = file_get_contents('php://input');
     //$objeto = json_decode($entityBody);
 }
开发者ID:beimarhuarachi,项目名称:compleapp,代码行数:28,代码来源:LoginController.php

示例2: execute

 public function execute()
 {
     $user = $this->getUser();
     if ($user->isBlocked()) {
         $this->dieUsageMsg('blockedtext');
     }
     if (!$user->isLoggedIn()) {
         $this->dieUsage('Must be logged in', 'token-impossible');
     }
     // Do not fatal out
     if (!class_exists('JWT')) {
         $this->dieUsage('JWT missing', 'token-impossible');
     }
     $config = $this->getConfig()->get('ContentTranslationCXServerAuth');
     $algorithm = $config['algorithm'];
     $key = $config['key'];
     if ($key === '') {
         $this->dieUsage('Key not configured', 'token-impossible');
     }
     $exp = time() + $config['age'];
     $token = array('sub' => $user->getName(), 'iat' => time(), 'exp' => $exp);
     $jwt = JWT::encode($token, $key, $algorithm);
     $this->getResult()->addValue(null, 'jwt', $jwt);
     $this->getResult()->addValue(null, 'exp', $exp);
 }
开发者ID:Rjaylyn,项目名称:mediawiki-extensions-ContentTranslation,代码行数:25,代码来源:ApiContentTranslationToken.php

示例3: is_authenticated

 function is_authenticated($user)
 {
     $CI =& get_instance();
     $CI->load->library('JWT');
     $CI->input->get_request_header('Authorization');
     return JWT::encode($token, JWT_TOKEN_SECRET);
 }
开发者ID:kyxer,项目名称:barrioos,代码行数:7,代码来源:jwt_helper.php

示例4: getToken

 public static function getToken($user)
 {
     //@todo, check to see if we have a token stored for this user
     $key = Settings::get('hash_salt');
     $token = array("uid" => $user->id(), "mail" => $user->getEmail());
     return \JWT::encode($token, $key);
 }
开发者ID:voryx,项目名称:ThruwayDrupal,代码行数:7,代码来源:Utils.php

示例5: loginset

 function loginset($id)
 {
     $userinfo = $this->User_data->userinfo($id);
     //读取用户数据
     //多说账号
     $token = array("short_name" => 'zustmanager', "user_key" => $userinfo['student_id'], "name" => $userinfo['username']);
     $duoshuoToken = JWT::encode($token, '97c1b8a2ce9f394b034232572c086196');
     $cookie = array('name' => 'duoshuo_token', 'value' => $duoshuoToken, 'expire' => '86500', 'domain' => '', 'path' => '/', 'secure' => FALSE);
     $this->input->set_cookie($cookie);
     $userinfo_session = array('username' => $userinfo['username'], 'student_id' => $userinfo['student_id'], 'head_img' => $userinfo['head_img'], 'major' => $userinfo['major'], 'classnum' => $userinfo['classnum'], 'email' => $userinfo['email'], 'qq' => $userinfo['qq']);
     $this->session->set_userdata($userinfo_session);
     //将用户数据写入session
     $logindate = array('status' => "1", 'lastLoginTime' => date("Y-m-d H:i:s"));
     $this->db->from('user')->where('student_id', $id)->update('user', $logindate);
     //更新用户登陆时间
     $log = array('student_id' => $userinfo['student_id'], 'username' => $userinfo['username'], 'events' => '登陆', 'time' => date("Y-m-d H:i:s"));
     $this->db->insert('log', $log);
     //记录事件 登陆
     /*      print_r($userinfo);//用户数据调出 调试用
     						echo "<hr>";
     						echo $this->session->userdata('username');
     						echo "<hr>";
     						echo "查询到此人";
     						echo date("Y-m-d H:i:s");*/
     $cookie = array('name' => 'zust_login', 'value' => $userinfo['student_id'] . '&' . $userinfo['password'], 'expire' => '86500', 'domain' => '', 'path' => '/', 'secure' => FALSE);
     $this->input->set_cookie($cookie);
     redirect(base_url('user/profile'));
 }
开发者ID:hemisu,项目名称:zustmanager,代码行数:28,代码来源:user_data.php

示例6: testKIDChooser

 function testKIDChooser()
 {
     $keys = array('1' => 'my_key', '2' => 'my_key2');
     $msg = JWT::encode('abc', $keys['1'], 'HS256', '1');
     $decoded = JWT::decode($msg, $keys, true);
     $this->assertEquals($decoded, 'abc');
 }
开发者ID:nightstomp,项目名称:php-jwt,代码行数:7,代码来源:JWTTest.php

示例7: login

 public function login($f3, $args)
 {
     self::check_configuration();
     $params = json_decode($f3->get('BODY'));
     if ($params->username && $params->password) {
         $login = new DB\Jig\Mapper($this->db, 'users.json');
         $temp = $login->find(array('(isset(@userName) && @userName == ?)', $params->username));
         if ($temp) {
             $first = __::first($temp);
             if (password_verify($params->password, $first['password'])) {
                 $date = new DateTime();
                 $date->add(new DateInterval('PT' . F3::get('custom.TTL') . 'H'));
                 $out = array('username' => $first['userName'], 'userid' => $first['_id'], 'ttl' => $date->format('Y-m-d H:i:s'), 'roles' => self::get_roles($first['_id']));
                 $jwt = JWT::encode($out, F3::get('custom.SUPER-KEY'));
                 echo json_encode(array('token' => $jwt, 'data' => array('firstName' => $first['firstName'], 'lastName' => $first['lastName'], 'userName' => $first['userName'])));
             } else {
                 self::wrong_login();
             }
         } else {
             self::wrong_login();
         }
     } else {
         self::wrong_login();
     }
 }
开发者ID:boliviasoftware,项目名称:micro-system-maker,代码行数:25,代码来源:login.php

示例8: onAfterOrderConfirm

    function onAfterOrderConfirm(&$order, &$methods, $method_id)
    {
        parent::onAfterOrderConfirm($order, $methods, $method_id);
        if ($this->payment_params->testingMode == true) {
            $this->payment_params->url = "https://sandbox.google.com/checkout/inapp/lib/buy.js";
        } else {
            $this->payment_params->url = "https://wallet.google.com/inapp/lib/buy.js";
        }
        if (empty($this->payment_params->sellerIdentifier)) {
            $this->app->enqueueMessage('You have to configure an seller Identifier for the googlewallet plugin payment first : check your plugin\'s parameters,
			on your website backend', 'error');
            return false;
        }
        if (empty($this->payment_params->sellerSecret)) {
            $this->app->enqueueMessage('You have to configure the seller Secret for the googlewallet plugin payment first : check your plugin\'s parameters,
			on your website backend', 'error');
            return false;
        }
        $amount = round($order->cart->full_total->prices[0]->price_value_with_tax, 2);
        $succes_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id=' . $order->order_id . $this->url_itemid;
        $cancel_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=order&task=cancel_order&order_id=' . $order->order_id . $this->url_itemid;
        $this->payment_params->succes_url = $succes_url;
        $this->payment_params->cancel_url = $cancel_url;
        $vars = array('iss' => trim($this->payment_params->sellerIdentifier), 'aud' => "Google", 'typ' => "google/payments/inapp/item/v1", 'exp' => time() + 3600, 'iat' => time(), 'request' => array('name' => $order->order_number, 'description' => "", 'price' => $amount, 'currencyCode' => $this->currency->currency_code, 'sellerData' => $order->order_id));
        $sellerSecret = $this->payment_params->sellerSecret;
        $token = JWT::encode($vars, $sellerSecret);
        $this->token = $token;
        $this->showPage('end');
        if ($this->payment_params->debug) {
            $this->writeToLog("Data send to googlewallet: \n\n\n" . print_r($vars, true));
        }
    }
开发者ID:q0821,项目名称:esportshop,代码行数:32,代码来源:googlewallet.php

示例9: encode

 /**
  * Converts and signs a PHP object or array into a JWT string.
  *
  * @param object|array $payload PHP object or array
  * @param string|null  $alg     The signing algorithm. Supported
  *                              algorithms are 'HS256', 'HS384' and 'HS512'
  *
  * @return string      A signed JWT
  */
 public function encode($payload, $alg = null)
 {
     if (empty($alg)) {
         $alg = $this->alg;
     }
     return \JWT::encode($payload, $this->key, $alg);
 }
开发者ID:samjarrett,项目名称:jwt-bundle,代码行数:16,代码来源:Manager.php

示例10: createToken

 /**
  * @access  public
  * @param   array|object $data     An object or array of data you wish
  *                                 to associate with the token. It will
  *                                 be available as the variable "auth" in
  *                                 the Firebase rules engine.
  * @param   object       $options  Optional. An associative array with
  *                                 the developer supplied options for this
  *                                 token. The following keys are recognized:
  *
  *                                   'admin': Set to true if you want this
  *                                   token to bypass all security rules.
  *                                   Defaults to false.
  *
  *                                   'debug': Set to true if you want to
  *                                   enable debug output from your security
  *                                   rules.
  *
  *                                   'expires': Set to a number (seconds
  *                                   since epoch) or a DateTime object that
  *                                   specifies the time at which the token
  *                                   should expire.
  *
  *                                   'notBefore': Set to a number (seconds
  *                                   since epoch) or a DateTime object that
  *                                   specifies the time before which the
  *                                   should be rejected by the server.
  *                                   
  *
  * @return  string       A Firebase auth token.
  */
 public function createToken($data, $options = null)
 {
     $funcName = 'Services_FirebaseTokenGenerator->createToken';
     // If $data is JSONifiable, let it pass.
     $json = json_encode($data);
     if (function_exists("json_last_error") && ($errno = json_last_error())) {
         $this->handleJSONError($errno);
     } else {
         if ($json === "null" && $data !== null) {
             throw new UnexpectedValueException("Data is not valid JSON");
         } else {
             if (empty($data) && empty($options)) {
                 throw new Exception($funcName + ": data is empty and no options are set.  This token will have no effect on Firebase.");
             }
         }
     }
     $claims = array();
     if (is_array($options)) {
         $claims = $this->_processOptions($options);
     }
     $claims["d"] = $data;
     $claims["v"] = $this->version;
     $claims["iat"] = time();
     return JWT::encode($claims, $this->secret, "HS256");
 }
开发者ID:jorgecabane93,项目名称:eMarkingWeb,代码行数:56,代码来源:FirebaseToken.php

示例11: encode

    /**
     * $scopes: should be an array with the follow structure:
     *
     *          'scope' => [
     *              'actions' => ['action1', 'action2']
     *          ],
     *          'scope2' => [
     *              'actions' => ['action1', 'action2']
     *          ]
     */
    public static function encode($client_id, $client_secret, $scopes = null, $custom_payload = null, $lifetime = 36000) {

            $time = time();

            $payload = array(
                "iat" => $time,
            );

            if ($scopes) {
                $payload["scopes"] = $scopes;
            }

            if ($scopes) {
                $custom_payload = array_merge($custom_payload, $payload);
            }

            $jti = md5(json_encode($payload));

            $payload['jti'] = $jti;
            $payload["exp"] = $time + $lifetime;
            $payload["aud"] = $client_id;

            $secret = base64_decode(strtr($client_secret, '-_', '+/'));

            $jwt = \JWT::encode($payload, $secret);

            return $jwt;


    }
开发者ID:pombredanne,项目名称:ArcherSys,代码行数:40,代码来源:Auth0JWT.php

示例12: login

 public function login()
 {
     // check ajax request
     if ($this->input->is_ajax_request()) {
         // check post parameter
         if (!$this->input->post("username") || !$this->input->post("password")) {
             echo json_encode(array("code" => 2, "response" => "Data insufficient"));
         }
         $uname = $this->input->post("username");
         $password = $this->input->post("password");
         // check login
         $user = $this->Login_mdl->login($uname, $password);
         // $sid=$this->Login_mdl->addsession($user->user_id,$user->user_name,$user->db_pass);
         if ($user !== false) {
             $chksesstbl = $this->Login_mdl->check_active_user($user->user_id);
             if ($chksesstbl) {
                 $this->Login_mdl->reset_active_session($user->user_id);
             }
             $sessionid = session_id();
             $sid = $this->Login_mdl->add_new_session($user->user_id, $sessionid);
             $user->iat = time();
             $user->exp = time() + 28800000;
             //8 hr extend; default 5000
             $user->sid = $sid;
             //encdoe token
             $jwt = JWT::encode($user, SECRECT_KEY);
             echo json_encode(array("data" => $user, 'token' => $jwt, "status" => array("code" => 0, 'success' => true, 'msg' => $sessionid)));
         } else {
             echo json_encode(array("data" => '', 'token' => '', "status" => array("code" => 0, 'success' => false, 'msg' => '')));
         }
     }
 }
开发者ID:eunovate,项目名称:AMS,代码行数:32,代码来源:Login_ctrl.php

示例13: getAll

 public function getAll()
 {
     // Token para probar el área con seguridad
     $test = array('iat' => time(), 'exp' => time() + LIFETIME, 'security' => 'Security Test');
     $jwt = JWT::encode($test, TOKEN);
     $this->data = array('mensaje' => 'Hola mundo!!!', 'token' => $jwt);
 }
开发者ID:Jamp,项目名称:sgas,代码行数:7,代码来源:test_controller.php

示例14: login

 public static function login(Cart66Account $account)
 {
     $name = $account->firstName . ' ' . $account->lastName;
     $email = $account->email;
     $externalId = $account->id;
     $organization = Cart66Setting::getValue('zendesk_organization');
     $key = Cart66Setting::getValue('zendesk_token');
     $prefix = Cart66Setting::getValue('zendesk_prefix');
     if (Cart66Setting::getValue('zendesk_jwt')) {
         $now = time();
         $token = array("jti" => md5($now . rand()), "iat" => $now, "name" => $name, "email" => $email);
         include_once CART66_PATH . "/pro/models/JWT.php";
         $jwt = JWT::encode($token, $key);
         // Redirect
         header("Location: https://" . $prefix . ".zendesk.com/access/jwt?jwt=" . $jwt);
         exit;
     } else {
         /* Build the message */
         $ts = isset($_GET['timestamp']) ? $_GET['timestamp'] : time();
         $message = $name . '|' . $email . '|' . $externalId . '|' . $organization . '|||' . $key . '|' . $ts;
         $hash = MD5($message);
         $remoteAuthUrl = 'http://' . $prefix . '.zendesk.com/access/remoteauth/';
         $arguments = array('name' => $name, 'email' => $email, 'external_id' => $externalId, 'organization' => $organization, 'timestamp' => $ts, 'hash' => $hash);
         $url = add_query_arg($arguments, $remoteAuthUrl);
         header("Location: " . $url);
         exit;
     }
 }
开发者ID:rbredow,项目名称:allyzabbacart,代码行数:28,代码来源:ZendeskRemoteAuth.php

示例15: createToken

 /**
  * @access  public
  * @param   array|object $data     An object or array of data you wish
  *                                 to associate with the token. It will
  *                                 be available as the variable "auth" in
  *                                 the Firebase rules engine.
  * @param   object       $options  Optional. An associative array with
  *                                 the developer supplied options for this
  *                                 token. The following keys are recognized:
  *
  *                                   'admin': Set to true if you want this
  *                                   token to bypass all security rules.
  *                                   Defaults to false.
  *
  *                                   'debug': Set to true if you want to
  *                                   enable debug output from your security
  *                                   rules.
  *
  *                                   'expires': Set to a number (seconds
  *                                   since epoch) or a DateTime object that
  *                                   specifies the time at which the token
  *                                   should expire.
  *
  *                                   'notBefore': Set to a number (seconds
  *                                   since epoch) or a DateTime object that
  *                                   specifies the time before which the
  *                                   should be rejected by the server.
  *
  *
  * @return  string       A Firebase auth token.
  */
 public function createToken($data, $options = null)
 {
     $funcName = 'Services_FirebaseTokenGenerator->createToken';
     // If $data is JSONifiable, let it pass.
     $json = json_encode($data);
     if (function_exists("json_last_error") && ($errno = json_last_error())) {
         $this->handleJSONError($errno);
     } else {
         if ($json === "null" && $data !== null) {
             throw new UnexpectedValueException("Data is not valid JSON");
         } else {
             if (empty($data) && empty($options)) {
                 throw new Exception($funcName . ": data is empty and no options are set.  This token will have no effect on Firebase.");
             }
         }
     }
     $claims = array();
     if (is_array($options)) {
         $claims = $this->_processOptions($options);
     }
     $this->_validateData($funcName, $data, isset($claims['admin']) && $claims["admin"] == true);
     $claims["d"] = $data;
     $claims["v"] = $this->version;
     $claims["iat"] = time();
     $token = JWT::encode($claims, $this->secret, "HS256");
     if (strlen($token) > 1024) {
         throw new Exception($funcName . ": generated token is too large.  Token cannot be larger than 1024 bytes.");
     }
     return $token;
 }
开发者ID:kellbot,项目名称:nestgraph,代码行数:61,代码来源:FirebaseToken.php


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