chore: some sso adjustments
This commit is contained in:
@@ -5,6 +5,11 @@ import qs from 'query-string';
|
|||||||
|
|
||||||
export const AUTH_API = '/auth';
|
export const AUTH_API = '/auth';
|
||||||
|
|
||||||
|
export const AUTH_CONFIG_API = '/auth-config';
|
||||||
|
|
||||||
|
export const AUTH_OIDC_LOGIN_API = '/auth/oidc/login';
|
||||||
|
export const AUTH_SAML_LOGIN_API = '/auth/saml/login';
|
||||||
|
|
||||||
export const login = async (
|
export const login = async (
|
||||||
params: { username: string; password: string },
|
params: { username: string; password: string },
|
||||||
options?: any
|
options?: any
|
||||||
@@ -38,3 +43,7 @@ export const updatePassword = async (params: any) => {
|
|||||||
data: params
|
data: params
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const fetchAuthConfig = async () => {
|
||||||
|
return request(AUTH_CONFIG_API);
|
||||||
|
};
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const Buttons = styled.div`
|
|||||||
align-items: flex-start;
|
align-items: flex-start;
|
||||||
gap: 24px;
|
gap: 24px;
|
||||||
width: 360px;
|
width: 360px;
|
||||||
|
margin-top: 52px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const BackButton = styled(Button).attrs({
|
const BackButton = styled(Button).attrs({
|
||||||
|
|||||||
@@ -1,24 +1,17 @@
|
|||||||
// hooks/useSSOAuth.ts
|
// hooks/useSSOAuth.ts
|
||||||
import { history, useIntl } from '@umijs/max';
|
import { history, useIntl } from '@umijs/max';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
AUTH_OIDC_LOGIN_API,
|
||||||
|
AUTH_SAML_LOGIN_API,
|
||||||
|
fetchAuthConfig
|
||||||
|
} from '../apis';
|
||||||
|
|
||||||
type LoginOption = {
|
type LoginOption = {
|
||||||
saml: boolean;
|
saml: boolean;
|
||||||
oidc: boolean;
|
oidc: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
// sso configuration
|
|
||||||
async function fetchAuthConfig(url: string) {
|
|
||||||
try {
|
|
||||||
const response = await fetch(url);
|
|
||||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
||||||
return response.json();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('OIDC config error:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSSOAuth({
|
export function useSSOAuth({
|
||||||
fetchUserInfo,
|
fetchUserInfo,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
@@ -42,16 +35,16 @@ export function useSSOAuth({
|
|||||||
const sso = params.get('sso');
|
const sso = params.get('sso');
|
||||||
|
|
||||||
const oidcLogin = () => {
|
const oidcLogin = () => {
|
||||||
window.location.href = '/auth/oidc/login';
|
window.location.href = AUTH_OIDC_LOGIN_API;
|
||||||
};
|
};
|
||||||
|
|
||||||
const samlLogin = () => {
|
const samlLogin = () => {
|
||||||
window.location.href = '/auth/saml/login';
|
window.location.href = AUTH_SAML_LOGIN_API;
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
try {
|
try {
|
||||||
const authConfig = await fetchAuthConfig('/auth-config');
|
const authConfig = await fetchAuthConfig();
|
||||||
setLoginOption({
|
setLoginOption({
|
||||||
oidc: !!authConfig.is_oidc,
|
oidc: !!authConfig.is_oidc,
|
||||||
saml: !!authConfig.is_saml
|
saml: !!authConfig.is_saml
|
||||||
@@ -70,7 +63,7 @@ export function useSSOAuth({
|
|||||||
}
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
setLoginOption({ oidc: false, saml: false });
|
setLoginOption({ oidc: false, saml: false });
|
||||||
onError?.(error);
|
onError?.(new Error(error));
|
||||||
onLoading?.(false);
|
onLoading?.(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { clearAtomStorage } from '@/atoms/utils';
|
|||||||
import { RequestConfig, history } from '@umijs/max';
|
import { RequestConfig, history } from '@umijs/max';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
|
|
||||||
|
// no base URL APIs
|
||||||
const NoBaseURLAPIs = ['/auth', '/v1-openai', '/version', '/proxy', '/update'];
|
const NoBaseURLAPIs = ['/auth', '/v1-openai', '/version', '/proxy', '/update'];
|
||||||
|
|
||||||
export const requestConfig: RequestConfig = {
|
export const requestConfig: RequestConfig = {
|
||||||
|
|||||||
Reference in New Issue
Block a user