mirror of
http://124.126.16.154:8888/singularity/hyperf-saml.git
synced 2026-01-15 05:35:09 +08:00
fix(sp): 修复了认证中心登录后,第一次访问其他系统未登录的问题
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user