Files
gpustack-ui/src/pages/login/apis/index.ts
T
gitlawrandjialin 36a1038d12 feat(login): render SSO button data-driven from /auth/config
The backend now advertises the active external auth provider on
``/auth/config`` as a single ``external_auth: {type, login_url} | null``
field (replacing the per-provider ``is_oidc`` / ``is_saml`` booleans).
This is the API needed to add CAS without per-provider UI conditionals.

Wire the login UI accordingly:

- ``useSSOAuth`` exposes a single ``loginWithExternalAuth()`` action and
  ``options.external_auth`` carrying the provider info; the OIDC- and
  SAML-specific exports are gone.
- ``LoginForm`` renders one SSO button whenever ``external_auth`` is
  set, navigating to ``login_url``. New providers (CAS, future LDAP /
  Azure AD / …) need zero UI changes — only a backend route.
- ``LocalUserForm`` and ``LoginKit`` type definitions drop the
  per-provider booleans.
2026-06-24 18:59:19 +08:00

69 lines
1.8 KiB
TypeScript

import { hideModalTemporarilyAtom } from '@/atoms/settings';
import { systemConfigAtom } from '@/atoms/system';
import { userAtom } from '@/atoms/user';
import { clearAtomStorage, clearStorageUserSettings } from '@/atoms/utils';
import { request } from '@umijs/max';
import qs from 'query-string';
export const AUTH_API = '/auth';
export const AUTH_CONFIG_API = '/auth/config';
export const login = async (
params: { username: string; password: string },
options?: any
) => {
return request(`${AUTH_API}/login`, {
method: 'POST',
data: qs.stringify(params),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
};
export const logout = async (userInfo?: any) => {
const res = await request(`${AUTH_API}/logout`, {
method: 'POST'
});
clearStorageUserSettings();
clearAtomStorage(userAtom);
clearAtomStorage(hideModalTemporarilyAtom);
clearAtomStorage(systemConfigAtom);
if (res?.logout_url) {
window.location.href = res.logout_url;
}
return;
};
export const accessToken = async () => {
return request(`${AUTH_API}/token`, {
method: 'POST'
});
};
export const updatePassword = async (params: any) => {
return request(`${AUTH_API}/update-password`, {
method: 'POST',
data: params
});
};
export type ExternalAuth = {
// Provider kind (``OIDC`` / ``SAML`` / ``CAS`` / …). Stays a free-form
// string so adding a new provider on the backend doesn't require a
// TypeScript change here.
type: string;
// Browser-facing login URL the SSO button should navigate to.
login_url: string;
};
export const fetchAuthConfig = async () => {
return request<{
external_auth: ExternalAuth | null;
first_time_setup: boolean;
get_initial_password_command: string;
}>(AUTH_CONFIG_API);
};