mirror of
https://github.com/certd/certd.git
synced 2026-05-16 05:07:32 +08:00
perf: 支持OIDC单点登录
This commit is contained in:
@@ -62,6 +62,13 @@ export type SysPublicSetting = {
|
||||
|
||||
// 第三方OAuth配置
|
||||
oauthEnabled?: boolean;
|
||||
// 是否自动注册用户
|
||||
oauthAutoRegister?: boolean;
|
||||
// 是否自动跳转第三方登录
|
||||
oauthAutoRedirect?: boolean;
|
||||
// 是否仅允许使用第三方登录
|
||||
oauthOnly?: boolean;
|
||||
// 第三方OAuth登录提供者配置
|
||||
oauthProviders?: Record<
|
||||
string,
|
||||
{
|
||||
|
||||
@@ -100,3 +100,10 @@ export async function loginByTwoFactor(data: any) {
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
export async function OauthProviders() {
|
||||
return await request({
|
||||
url: "/oauth/providers",
|
||||
method: "post",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import { mitter } from "/src/utils/util.mitt";
|
||||
import { resetAllStores, useAccessStore } from "/@/vben/stores";
|
||||
|
||||
import { useUserStore as vbenUserStore } from "/@/vben/stores/modules/user";
|
||||
import { request } from "/@/api/service";
|
||||
|
||||
interface UserState {
|
||||
userInfo: Nullable<UserInfoRes>;
|
||||
@@ -116,15 +117,38 @@ export const useUserStore = defineStore({
|
||||
* @description: logout
|
||||
*/
|
||||
async logout(goLogin = true, from401 = false) {
|
||||
if (!from401 && this.getToken) {
|
||||
try {
|
||||
await UserApi.logout(); //主要是清空cookie
|
||||
} catch (e) {
|
||||
console.error("注销登录请求失败:", e);
|
||||
}
|
||||
}
|
||||
|
||||
this.resetState();
|
||||
resetAllStores();
|
||||
if (!from401) {
|
||||
await UserApi.logout(); //主要是清空cookie
|
||||
}
|
||||
// 第三方登录注销
|
||||
await this.oauthLogout();
|
||||
goLogin && router.push("/login");
|
||||
mitter.emit("app.logout");
|
||||
},
|
||||
|
||||
async oauthLogout() {
|
||||
const providers = await UserApi.OauthProviders();
|
||||
for (const provider of providers) {
|
||||
if (provider.logoutUrl) {
|
||||
try {
|
||||
await request({
|
||||
url: provider.logoutUrl,
|
||||
method: "get",
|
||||
withCredentials: true,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("注销第三方登录失败:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @description: Confirm before logging out
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user