Signs the data
public sign ( Lcobucci\JWT\Signer $signer, Lcobucci\JWT\Signer\Key $key ) : |
||
$signer | Lcobucci\JWT\Signer | |
$key | Lcobucci\JWT\Signer\Key | |
리턴 |
/** * * @param string $secret * @param int $accountId * @param int $arkonUserId * @param \DateTimeZone $timeZone */ public function __construct($secret, $accountId, $arkonUserId, \DateTimeZone $timeZone = null) { $signer = new Sha(); $this->token = (new Builder())->set(self::CLAIM_ACCOUNT_ID, $accountId); if ($arkonUserId) { $this->token->set(self::CLAIM_ARKON_USER_ID, $arkonUserId); } if (!is_null($timeZone)) { $this->token->set(self::CLAIM_TIME_ZONE, $timeZone->getName()); } $date = new \DateTime(null, new \DateTimeZone(self::JWT_TIME_ZONE)); $this->token->set(self::CLAIM_ISSUED_AT_TIME, $date->format(self::JWT_DATE_FORMAT)); $this->token->sign($signer, $secret); }
throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid username or password.'); } // Generate new JSON Web Token. $builder = new JWT\Builder(); $builder ->setNotBefore(time()) ->setIssuer($request->getSchemeAndHttpHost()) ->setId($user['_id']->{'$id'}) ; foreach (['name', 'email', 'given_name', 'family_name', 'email_verified', 'gender'] as $field) { $builder->set($field, $user[$field]); } $builder->sign(new JWT\Signer\Rsa\Sha256(), $privateKey); $token = $builder->getToken(); return new Response($token, 200, ['Access-Control-Allow-Origin' => '*', 'Content-Type' => 'application/jwt']); }); $app->get('/images', function(Request $request) use($app, $images) { $image = $images->find()->sort(['date' => -1]); $images = []; while ($next = $image->getNext()) { $images[] = ImageData::fromDb($request, $next); } return new JsonResponse($images, 200, ['Access-Control-Allow-Origin' => '*']); });
/** * @param \Lcobucci\JWT\Builder $builder * @return \Lcobucci\JWT\Builder */ public function sign(Builder $builder) { return $builder->sign($this->signer, $this->key); }
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; }
/** * @return string JWT string */ public function getTokenString() : string { /** * Build Token */ $builder = new Builder(); $builder->setIssuer(self::ISSUER); $builder->setExpiration((new \DateTime($this->configuration->get('Cookie.TTL')))->getTimestamp()); foreach ($this->values as $key => $value) { $builder->set($key, $value); } /** * Sign and generate new token */ $builder->sign(new Sha256(), $this->configuration->get('Cookie.Signer.Key')); $token = $builder->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(); }