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