diff --git a/src/Services/Sp/Assertion.php b/src/Services/Sp/Assertion.php index a7e88e8..66f4e25 100644 --- a/src/Services/Sp/Assertion.php +++ b/src/Services/Sp/Assertion.php @@ -103,23 +103,27 @@ class Assertion // 据此判断是登录还是isLogin $relayState = $this->base->getRelayStateFromResponse($response); - if (!is_null($relayState)) { - // 登录时的处理 - { - // 记录映射 - $key = "{$redis_prefix}user:token_map:{$user['uid']}"; - $this->stdoutLogger->info('allow multi device online: ' . $allow_multi_online); - if (!$allow_multi_online) { - // 顶掉之前已经登录的用户 - $this->redis->del($key); - $this->stdoutLogger->info('删除现有记录'); - $this->stdoutLogger->info($this->redis->type($key)); - } - $this->redis->hSet($key, $user['originToken'], $token); - $this->stdoutLogger->info('更新后的现有记录'); + + // 记录映射 + { + $key = "{$redis_prefix}user:token_map:{$user['uid']}"; + $this->stdoutLogger->info('allow multi device online: ' . $allow_multi_online); + + // 登录时,顶掉之前用户 + if (!is_null($relayState) && !$allow_multi_online) { + // 顶掉之前已经登录的用户 + $this->redis->del($key); + $this->stdoutLogger->info('删除现有记录'); $this->stdoutLogger->info($this->redis->type($key)); } - + // 如果是 assertion 接口的回调,设置后可实现"单点登录后,任一系统都能自动登录" + $this->redis->hSet($key, $user['originToken'], $token); + $this->stdoutLogger->info('更新后的现有记录'); + $this->stdoutLogger->info($this->redis->type($key)); + } + + if (!is_null($relayState)) { + // 登录时的处理 $url = config('saml.client.landing_host'); $login_status_cookie = new Cookie( 'is_login', diff --git a/src/Services/Sp/Sso.php b/src/Services/Sp/Sso.php index d3477af..63e6040 100644 --- a/src/Services/Sp/Sso.php +++ b/src/Services/Sp/Sso.php @@ -12,6 +12,8 @@ declare(strict_types=1); namespace Singularity\HyperfSaml\Services\Sp; use Hyperf\Utils\Codec\Json; +use Singularity\HDK\Core\Constants\CommonErrorCode; +use Singularity\HDK\Core\Exceptions\Forbidden; use Swoole\Exception; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Di\Annotation\Inject; @@ -19,8 +21,6 @@ use Hyperf\HttpServer\Contract\RequestInterface; use Hyperf\HttpServer\Contract\ResponseInterface; use Hyperf\Redis\Redis; use Psr\Http\Message\ResponseInterface as PsrResponseInterface; -use Singularity\HDK\Utils\Constants\CommonErrorCode; -use Singularity\HDK\Utils\Exceptions\Forbidden; use Singularity\HyperfSaml\Services\Base; use Teapot\StatusCode\RFC\RFC7231; @@ -137,6 +137,7 @@ class Sso } break; case SWOOLE_REDIS_TYPE_NOT_FOUND: + break; default: throw new \Exception(code: CommonErrorCode::SERVER_ERROR); }