revert(iam): 统一登录 - 撤销 IAM Hub 接入
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\adminapi\controller;
|
||||
|
||||
use app\common\service\iam\IamHubException;
|
||||
use app\common\service\iam\IamRevocationService;
|
||||
use think\facade\Log;
|
||||
|
||||
class IamController extends BaseAdminController
|
||||
{
|
||||
public array $notNeedLogin = ['revocation'];
|
||||
|
||||
public function revocation()
|
||||
{
|
||||
try {
|
||||
(new IamRevocationService())->apply(
|
||||
(string) $this->request->getContent(),
|
||||
(string) $this->request->header('X-IAM-Signature', ''),
|
||||
(string) $this->request->header('X-IAM-Event-ID', '')
|
||||
);
|
||||
return response('', 204);
|
||||
} catch (IamHubException $error) {
|
||||
return json([
|
||||
'code' => 0,
|
||||
'show' => 0,
|
||||
'msg' => $error->getMessage(),
|
||||
'data' => [],
|
||||
], $error->httpStatus());
|
||||
} catch (\Throwable $error) {
|
||||
Log::error('IAM Hub revocation failed: ' . get_class($error));
|
||||
return json([
|
||||
'code' => 0,
|
||||
'show' => 0,
|
||||
'msg' => 'IAM Hub revocation failed',
|
||||
'data' => [],
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,6 @@ namespace app\adminapi\controller;
|
||||
|
||||
use app\adminapi\logic\LoginLogic;
|
||||
use app\adminapi\validate\LoginValidate;
|
||||
use app\common\service\iam\IamAdminIdentityService;
|
||||
use app\common\service\iam\IamExchangeService;
|
||||
use app\common\service\iam\IamHubException;
|
||||
use app\common\service\iam\IamOidcService;
|
||||
use think\facade\Log;
|
||||
|
||||
/**
|
||||
* 管理员登录控制器
|
||||
@@ -29,57 +24,7 @@ use think\facade\Log;
|
||||
*/
|
||||
class LoginController extends BaseAdminController
|
||||
{
|
||||
public array $notNeedLogin = [
|
||||
'account', 'workWechatConfig', 'workWechatLogin', 'checkDbColumn', 'changeFirstPassword',
|
||||
'iamConfig', 'iamStart', 'iamCallback', 'iamExchange',
|
||||
];
|
||||
|
||||
public function iamConfig()
|
||||
{
|
||||
return $this->data([
|
||||
'enabled' => (new IamOidcService())->enabled(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function iamStart()
|
||||
{
|
||||
try {
|
||||
return redirect((new IamOidcService())->begin());
|
||||
} catch (IamHubException $error) {
|
||||
return json(['code' => 0, 'show' => 1, 'msg' => $error->getMessage(), 'data' => []], $error->httpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
public function iamCallback()
|
||||
{
|
||||
$successUrl = (string) config('iam_hub.login_success_url', '/admin/login');
|
||||
try {
|
||||
$code = trim((string) $this->request->get('code', ''));
|
||||
$state = trim((string) $this->request->get('state', ''));
|
||||
if ($code === '' || $state === '') {
|
||||
throw new IamHubException('统一身份登录回调参数缺失');
|
||||
}
|
||||
$claims = (new IamOidcService())->callback($code, $state);
|
||||
$login = (new IamAdminIdentityService())->login($claims, 1);
|
||||
$exchange = new IamExchangeService((int) config('iam_hub.exchange_ttl_seconds', 60));
|
||||
$exchangeCode = $exchange->store($login);
|
||||
return redirect($successUrl . '#iam_code=' . rawurlencode($exchangeCode));
|
||||
} catch (\Throwable $error) {
|
||||
Log::error('IAM Hub admin login callback failed: ' . get_class($error));
|
||||
return redirect($successUrl . '#iam_error=1');
|
||||
}
|
||||
}
|
||||
|
||||
public function iamExchange()
|
||||
{
|
||||
$code = trim((string) $this->request->post('code', ''));
|
||||
$exchange = new IamExchangeService((int) config('iam_hub.exchange_ttl_seconds', 60));
|
||||
$login = $exchange->consume($code);
|
||||
if ($login === null) {
|
||||
return $this->fail('统一身份登录凭证无效或已过期');
|
||||
}
|
||||
return $this->data($login);
|
||||
}
|
||||
public array $notNeedLogin = ['account', 'workWechatConfig', 'workWechatLogin', 'checkDbColumn', 'changeFirstPassword'];
|
||||
|
||||
/**
|
||||
* @notes 账号登录
|
||||
@@ -216,4 +161,4 @@ class LoginController extends BaseAdminController
|
||||
(new LoginLogic())->logout($this->adminInfo);
|
||||
return $this->success();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user