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

feat: 修改授权方式

parent 7e3b5e67
...@@ -29,9 +29,6 @@ class Application implements ClientInterface ...@@ -29,9 +29,6 @@ class Application implements ClientInterface
private const TOKEN_CACHE_KEY = "Auth.%s"; private const TOKEN_CACHE_KEY = "Auth.%s";
/** @var string jwtToken */
private $jwtToken = "";
/** @var Option $option */ /** @var Option $option */
private $option; private $option;
...@@ -158,28 +155,26 @@ class Application implements ClientInterface ...@@ -158,28 +155,26 @@ class Application implements ClientInterface
$stack->push($middleware); $stack->push($middleware);
} }
if ($request->authorization()) { if ($request->authorization()) {
if ($this->jwtToken === "") { try {
try { $jwtToken = $this->getAccessTokenFromCache();
$this->jwtToken = $this->getAccessTokenFromCache(); $authMiddleware = $this->option->getAuthorizationMiddleware();
} catch (CacheInvalidArgumentException $exception) { $stack->push(new $authMiddleware($jwtToken));
// 缓存异常 } catch (CacheInvalidArgumentException $exception) {
throw new ApplicationException("auth cache error " . $exception->getMessage()); // 缓存异常
} catch (TransferException $exception) { throw new ApplicationException("auth cache error " . $exception->getMessage());
// 超时异常 } catch (TransferException $exception) {
if ($this->logger) { // 超时异常
$this->logger->error("sdk error, authorization timeout."); if ($this->logger) {
} $this->logger->error("sdk error, authorization timeout.");
throw new TimeOutExcetpion($request); }
} catch (RuntimeException|InvalidArgumentException $exception) { throw new TimeOutExcetpion($request);
// 参数异常 } catch (RuntimeException|InvalidArgumentException $exception) {
if ($this->logger) { // 参数异常
$this->logger->error("sdk error, cause by:" . $exception->getMessage()); if ($this->logger) {
} $this->logger->error("sdk error, cause by:" . $exception->getMessage());
throw new ApplicationException($exception->getMessage(), $request, [], $exception);
} }
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