fix(sso): User类的使用问题造成的响应格式错误

Signed-off-by: 李东云 <dongyun.li@luxcreo.ai>
This commit is contained in:
李东云
2022-05-05 16:09:30 +08:00
parent 9b96e565f1
commit 5fee108c9f

View File

@@ -7,6 +7,7 @@
* Created on 2022/3/29
*/
declare(strict_types=1);
namespace Singularity\HyperfSaml\Services\Sp;
use Exception;
@@ -77,9 +78,9 @@ class Assertion
*
* @param \LightSaml\Model\Protocol\Response $response
*
* @return \Psr\Http\Message\ResponseInterface|\Singularity\HDK\Account\Resource\User
* @return array|\Psr\Http\Message\ResponseInterface|\Singularity\HDK\Account\Resource\User
*/
public function consumeResponse(Response $response): \Psr\Http\Message\ResponseInterface|User
public function consumeResponse(Response $response): array|\Psr\Http\Message\ResponseInterface
{
$allow_multi_online = config('saml.allow_multi_online');
$redis_prefix = config('common.redis.prefix');
@@ -88,14 +89,13 @@ class Assertion
$user = $this->base->getAllAttributes($response);
$user = array_replace($oldUser?->toArray() ?? [], $user->toArray());
$user = new User($user);
// 更新
$token = $this->authentication->generate($user);
$token = $this->authentication->generate(new User($user));
// 记录映射
$key = "{$redis_prefix}user:token_map:{$user['uid']}";
if ($allow_multi_online) {
$this->redis->hSet($key, $user->originToken, $token);
$this->redis->hSet($key, $user['originToken'], $token);
} else {
$this->redis->set($key, $token);
}