Commit 659c7772 authored by 李晓东's avatar 李晓东

feat: 修改授权方式

parent 7e3b5e67
......@@ -29,9 +29,6 @@ class Application implements ClientInterface
private const TOKEN_CACHE_KEY = "Auth.%s";
/** @var string jwtToken */
private $jwtToken = "";
/** @var Option $option */
private $option;
......@@ -158,28 +155,26 @@ class Application implements ClientInterface
$stack->push($middleware);
}
if ($request->authorization()) {
if ($this->jwtToken === "") {
try {
$this->jwtToken = $this->getAccessTokenFromCache();
} catch (CacheInvalidArgumentException $exception) {
// 缓存异常
throw new ApplicationException("auth cache error " . $exception->getMessage());
} catch (TransferException $exception) {
// 超时异常
if ($this->logger) {
$this->logger->error("sdk error, authorization timeout.");
}
throw new TimeOutExcetpion($request);
} catch (RuntimeException|InvalidArgumentException $exception) {
// 参数异常
if ($this->logger) {
$this->logger->error("sdk error, cause by:" . $exception->getMessage());
}
throw new ApplicationException($exception->getMessage(), $request, [], $exception);
try {
$jwtToken = $this->getAccessTokenFromCache();
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($jwtToken));
} catch (CacheInvalidArgumentException $exception) {
// 缓存异常
throw new ApplicationException("auth cache error " . $exception->getMessage());
} catch (TransferException $exception) {
// 超时异常
if ($this->logger) {
$this->logger->error("sdk error, authorization timeout.");
}
throw new TimeOutExcetpion($request);
} catch (RuntimeException|InvalidArgumentException $exception) {
// 参数异常
if ($this->logger) {
$this->logger->error("sdk error, cause by:" . $exception->getMessage());
}
throw new ApplicationException($exception->getMessage(), $request, [], $exception);
}
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($this->jwtToken));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment