Ejemplo n.º 1
0
 /**
  * @return Builder
  */
 protected function builder()
 {
     $builder = new Builder();
     $time = time();
     $builder->setIssuedAt($time)->setExpiration($time + config('jwt.ttl'));
     return $builder;
 }
Ejemplo n.º 2
0
 /**
  * create token with socketId
  *
  * @param  [string] $socketId
  * @return [string]
  */
 private function createToken()
 {
     // builder for jwt
     $builder = new Builder();
     // current time
     $time = time();
     return $builder->setIssuedAt($time)->setNotBefore($time)->setExpiration($time + 10000)->getToken();
 }
Ejemplo n.º 3
0
 public function createToken(AuthenticatableContract $user)
 {
     $payload = $this->buildTokenPayload($user);
     $this->builder->unsign();
     // set additional payload data
     foreach ($payload as $key => $value) {
         $this->builder->set($key, $value);
     }
     $now = time();
     $lifespanSecs = $this->config['lifespan'] * 60;
     return $this->builder->setIssuedAt($now)->setExpiration($now + $lifespanSecs)->sign(new $this->signer(), $this->secret)->getToken();
     // Retrieves the generated token
 }
Ejemplo n.º 4
-1
 private function generateToken(UserView $user)
 {
     $signer = new Sha256();
     $issuedAt = time();
     $key = $this->configuration->get('auth-key');
     $ttl = $this->configuration->get('auth-ttl');
     $expiration = is_null($ttl) ? (int) $ttl : 3600;
     $builder = new Builder();
     $builder->setIssuedAt($issuedAt)->setNotBefore($issuedAt + 1)->setExpiration($issuedAt + $expiration)->set('uid', $user->getId());
     $issuer = $this->configuration->get('auth-issuer');
     $audience = $this->configuration->get('auth-audience');
     if ($issuer != null) {
         $builder->setIssuer($issuer);
     }
     if ($audience != null) {
         $builder->setAudience($audience);
     }
     $token = $builder->sign($signer, $key)->getToken();
     return (string) $token;
 }
 /**
  * Generates a user token
  * @return string
  */
 public function getToken($data = null)
 {
     $time = time();
     $signer = new Sha256();
     $token = new Builder();
     $token->setIssuer(Router::url('/', true));
     $token->setAudience($this->request->clientIp());
     $token->setIssuedAt($time);
     $token->setNotBefore($time);
     $token->setExpiration($time + Configure::read('Security.timeout'));
     $token->set('data', json_encode($data));
     return (string) $token->sign($signer, Configure::read('Security.salt'))->getToken();
 }