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,9 +155,10 @@ class Application implements ClientInterface ...@@ -158,9 +155,10 @@ class Application implements ClientInterface
$stack->push($middleware); $stack->push($middleware);
} }
if ($request->authorization()) { if ($request->authorization()) {
if ($this->jwtToken === "") {
try { try {
$this->jwtToken = $this->getAccessTokenFromCache(); $jwtToken = $this->getAccessTokenFromCache();
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($jwtToken));
} catch (CacheInvalidArgumentException $exception) { } catch (CacheInvalidArgumentException $exception) {
// 缓存异常 // 缓存异常
throw new ApplicationException("auth cache error " . $exception->getMessage()); throw new ApplicationException("auth cache error " . $exception->getMessage());
...@@ -178,9 +176,6 @@ class Application implements ClientInterface ...@@ -178,9 +176,6 @@ class Application implements ClientInterface
throw new ApplicationException($exception->getMessage(), $request, [], $exception); throw new ApplicationException($exception->getMessage(), $request, [], $exception);
} }
} }
$authMiddleware = $this->option->getAuthorizationMiddleware();
$stack->push(new $authMiddleware($this->jwtToken));
}
} }
$options = [ $options = [
......
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