mirror of
http://124.126.16.154:8888/singularity/hyperf-saml.git
synced 2026-01-15 03:45:06 +08:00
fix(auth): 修复鉴权
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HyperfSaml\Services\Sp;
|
||||
|
||||
use Hyperf\Utils\Codec\Json;
|
||||
use Swoole\Exception;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -38,22 +39,12 @@ class Sso
|
||||
private string $acsUrl;
|
||||
private string $issuer;
|
||||
|
||||
/**
|
||||
* @Inject
|
||||
* @var \Hyperf\Redis\Redis
|
||||
*/
|
||||
private Redis $redis;
|
||||
|
||||
/**
|
||||
* @Inject()
|
||||
* @var \Hyperf\Contract\StdoutLoggerInterface
|
||||
*/
|
||||
private StdoutLoggerInterface $stdoutLogger;
|
||||
|
||||
public function __construct(
|
||||
private Base $base,
|
||||
private RequestInterface $request,
|
||||
private ResponseInterface $response,
|
||||
private Redis $redis,
|
||||
private StdoutLoggerInterface $stdoutLogger
|
||||
) {
|
||||
$this->idpId = config('saml.server.idp_id');
|
||||
$this->idpAssertionUrl = config('saml.server.idp_assertion_url');
|
||||
@@ -123,6 +114,7 @@ class Sso
|
||||
$type = $this->redis->type($key);
|
||||
|
||||
try {
|
||||
$this->stdoutLogger->info('user_token redis type: ' . $type);
|
||||
switch ($type) {
|
||||
case SWOOLE_REDIS_TYPE_STRING:
|
||||
// 旧的值
|
||||
@@ -134,10 +126,13 @@ class Sso
|
||||
break;
|
||||
case SWOOLE_REDIS_TYPE_HASH:
|
||||
$origin_token = $this->redis->hKeys($key);
|
||||
$this->stdoutLogger->info('user_token redis keys: ' . Json::encode($origin_token));
|
||||
$origin_token = array_pop($origin_token);
|
||||
$latest_token = $this->redis->exists($key . ':' . $origin_token);
|
||||
$this->stdoutLogger->info('user_token redis key: ' . $origin_token);
|
||||
$latest_token = $this->redis->hGet($key, $origin_token);
|
||||
$this->stdoutLogger->info('user_token redis value isset: ' . $latest_token);
|
||||
|
||||
if (empty($latest_token)) {
|
||||
if (empty($latest_token) || $latest_token !== $token) {
|
||||
throw new Exception(code: CommonErrorCode::AUTH_SESSION_CREATED_AT_ERROR);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user