2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

align names with allauth

This commit is contained in:
Matthias Mair
2025-01-10 02:52:05 +01:00
parent ec6ee2cbed
commit 5661b93910
7 changed files with 48 additions and 45 deletions

View File

@ -35,9 +35,9 @@ export function AuthenticationForm() {
}); });
const simpleForm = useForm({ initialValues: { email: '' } }); const simpleForm = useForm({ initialValues: { email: '' } });
const [classicLoginMode, setMode] = useDisclosure(true); const [classicLoginMode, setMode] = useDisclosure(true);
const [auth_settings, sso_enabled, password_forgotten_enabled] = const [auth_config, sso_enabled, password_forgotten_enabled] =
useServerApiState((state) => [ useServerApiState((state) => [
state.auth_settings, state.auth_config,
state.sso_enabled, state.sso_enabled,
state.password_forgotten_enabled state.password_forgotten_enabled
]); ]);
@ -107,7 +107,7 @@ export function AuthenticationForm() {
{sso_enabled() ? ( {sso_enabled() ? (
<> <>
<Group grow mb='md' mt='md'> <Group grow mb='md' mt='md'>
{auth_settings?.socialaccount.providers.map((provider) => ( {auth_config?.socialaccount.providers.map((provider) => (
<SsoButton provider={provider} key={provider.id} /> <SsoButton provider={provider} key={provider.id} />
))} ))}
</Group> </Group>
@ -205,9 +205,9 @@ export function RegistrationForm() {
} }
}); });
const navigate = useNavigate(); const navigate = useNavigate();
const [auth_settings, registration_enabled, sso_registration] = const [auth_config, registration_enabled, sso_registration] =
useServerApiState((state) => [ useServerApiState((state) => [
state.auth_settings, state.auth_config,
state.registration_enabled, state.registration_enabled,
state.sso_registration_enabled state.sso_registration_enabled
]); ]);
@ -228,7 +228,7 @@ export function RegistrationForm() {
await ensureCsrf(); await ensureCsrf();
api api
.post(apiUrl(ApiEndpoints.user_register), vals, { .post(apiUrl(ApiEndpoints.auth_signup), vals, {
headers: { Authorization: '' } headers: { Authorization: '' }
}) })
.then((ret) => { .then((ret) => {
@ -321,7 +321,7 @@ export function RegistrationForm() {
)} )}
{sso_registration() && ( {sso_registration() && (
<Group grow mb='md' mt='md'> <Group grow mb='md' mt='md'>
{auth_settings?.socialaccount.providers.map((provider) => ( {auth_config?.socialaccount.providers.map((provider) => (
<SsoButton provider={provider} key={provider.id} /> <SsoButton provider={provider} key={provider.id} />
))} ))}
</Group> </Group>

View File

@ -18,15 +18,16 @@ export enum ApiEndpoints {
user_simple_login = 'email/generate/', user_simple_login = 'email/generate/',
user_reset = 'auth/password/reset/', // TODO change user_reset = 'auth/password/reset/', // TODO change
user_reset_set = 'auth/password/reset/confirm/', // TODO change user_reset_set = 'auth/password/reset/confirm/', // TODO change
user_change_password = 'auth/v1/account/password/change', auth_pwd_change = 'auth/v1/account/password/change',
user_sso = 'auth/v1/account/providers', auth_login = 'auth/v1/auth/login',
user_login = 'auth/v1/auth/login', auth_login_2fa = 'auth/v1/auth/2fa/authenticate',
user_login_mfa = 'auth/v1/auth/2fa/authenticate', auth_session = 'auth/v1/auth/session',
user_logout = 'auth/v1/auth/session', auth_signup = 'auth/v1/auth/signup',
user_register = 'auth/v1/auth/signup', auth_authenticators = 'auth/v1/account/authenticators',
user_mfa = 'auth/v1/account/authenticators', auth_email = 'auth/v1/account/email',
user_emails = 'auth/v1/account/email', auth_providers = 'auth/v1/account/providers',
login_provider_redirect = 'auth/v1/auth/provider/redirect', auth_provider_redirect = 'auth/v1/auth/provider/redirect',
auth_config = 'auth/v1/config',
// Generic API endpoints // Generic API endpoints
currency_list = 'currency/exchange/', currency_list = 'currency/exchange/',
@ -50,7 +51,6 @@ export enum ApiEndpoints {
icons = 'icons/', icons = 'icons/',
selectionlist_list = 'selection/', selectionlist_list = 'selection/',
selectionlist_detail = 'selection/:id/', selectionlist_detail = 'selection/:id/',
securtiy_settings = 'auth/v1/config',
// Barcode API endpoints // Barcode API endpoints
barcode = 'barcode/', barcode = 'barcode/',

View File

@ -74,7 +74,7 @@ export const doBasicLogin = async (
clearCsrfCookie(); clearCsrfCookie();
await ensureCsrf(); await ensureCsrf();
const login_url = apiUrl(ApiEndpoints.user_login); const login_url = apiUrl(ApiEndpoints.auth_login);
let loginDone = false; let loginDone = false;
let success = false; let success = false;
@ -129,7 +129,7 @@ export const doLogout = async (navigate: NavigateFunction) => {
// Logout from the server session // Logout from the server session
if (isLoggedIn() || !!getCsrfCookie()) { if (isLoggedIn() || !!getCsrfCookie()) {
await authApi(apiUrl(ApiEndpoints.user_logout), undefined, 'delete').catch( await authApi(apiUrl(ApiEndpoints.auth_session), undefined, 'delete').catch(
() => {} () => {}
); );
showLoginNotification({ showLoginNotification({
@ -203,7 +203,7 @@ export function handleMfaLogin(
values: { code: string } values: { code: string }
) { ) {
const { setToken } = useUserState.getState(); const { setToken } = useUserState.getState();
authApi(apiUrl(ApiEndpoints.user_login_mfa), undefined, 'post', { authApi(apiUrl(ApiEndpoints.auth_login_2fa), undefined, 'post', {
code: values.code code: values.code
}).then((response) => { }).then((response) => {
setToken(response.data.meta.access_token); setToken(response.data.meta.access_token);
@ -300,7 +300,7 @@ export function ProviderLogin(
process: process, process: process,
csrfmiddlewaretoken: getCsrfCookie() csrfmiddlewaretoken: getCsrfCookie()
}; };
const url = `${host}${apiUrl(ApiEndpoints.login_provider_redirect)}`; const url = `${host}${apiUrl(ApiEndpoints.auth_provider_redirect)}`;
post(url, values); post(url, values);
} }

View File

@ -69,7 +69,7 @@ export default function Set_Password() {
// Set password with call to backend // Set password with call to backend
api api
.post(apiUrl(ApiEndpoints.user_change_password), { .post(apiUrl(ApiEndpoints.auth_pwd_change), {
current_password: simpleForm.values.current_password, current_password: simpleForm.values.current_password,
new_password: simpleForm.values.new_password2 new_password: simpleForm.values.new_password2
}) })

View File

@ -22,12 +22,14 @@ import { YesNoButton } from '../../../../components/buttons/YesNoButton';
import { ApiEndpoints } from '../../../../enums/ApiEndpoints'; import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
import { ProviderLogin, authApi } from '../../../../functions/auth'; import { ProviderLogin, authApi } from '../../../../functions/auth';
import { apiUrl, useServerApiState } from '../../../../states/ApiState'; import { apiUrl, useServerApiState } from '../../../../states/ApiState';
import type { Provider, SecuritySetting } from '../../../../states/states'; import type { AuthConfig, Provider } from '../../../../states/states';
export function SecurityContent() { export function SecurityContent() {
const [auth_settings, sso_enabled, mfa_enabled] = useServerApiState( const [auth_config, sso_enabled, mfa_enabled] = useServerApiState((state) => [
(state) => [state.auth_settings, state.sso_enabled, state.mfa_enabled] state.auth_config,
); state.sso_enabled,
state.mfa_enabled
]);
return ( return (
<Stack> <Stack>
@ -39,7 +41,7 @@ export function SecurityContent() {
<Trans>Single Sign On Accounts</Trans> <Trans>Single Sign On Accounts</Trans>
</Title> </Title>
{sso_enabled() ? ( {sso_enabled() ? (
<SsoContent auth_settings={auth_settings} /> <SsoContent auth_config={auth_config} />
) : ( ) : (
<Alert <Alert
icon={<IconAlertCircle size='1rem' />} icon={<IconAlertCircle size='1rem' />}
@ -81,7 +83,7 @@ function EmailContent() {
const { isLoading, data, refetch } = useQuery({ const { isLoading, data, refetch } = useQuery({
queryKey: ['emails'], queryKey: ['emails'],
queryFn: () => queryFn: () =>
authApi(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data.data) authApi(apiUrl(ApiEndpoints.auth_email)).then((res) => res.data.data)
}); });
function runServerAction( function runServerAction(
@ -90,7 +92,7 @@ function EmailContent() {
) { ) {
const vals: any = data || { email: value }; const vals: any = data || { email: value };
console.log('vals', vals); console.log('vals', vals);
authApi(apiUrl(ApiEndpoints.user_emails), undefined, action, vals) authApi(apiUrl(ApiEndpoints.auth_email), undefined, action, vals)
.then(() => { .then(() => {
refetch(); refetch();
}) })
@ -198,18 +200,18 @@ function ProviderButton({ provider }: Readonly<{ provider: Provider }>) {
} }
function SsoContent({ function SsoContent({
auth_settings auth_config
}: Readonly<{ auth_settings: SecuritySetting | undefined }>) { }: Readonly<{ auth_config: AuthConfig | undefined }>) {
const [value, setValue] = useState<string>(''); const [value, setValue] = useState<string>('');
const [currentProviders, setCurrentProviders] = useState<Provider[]>(); const [currentProviders, setCurrentProviders] = useState<Provider[]>();
const { isLoading, data, refetch } = useQuery({ const { isLoading, data, refetch } = useQuery({
queryKey: ['sso-list'], queryKey: ['sso-list'],
queryFn: () => queryFn: () =>
authApi(apiUrl(ApiEndpoints.user_sso)).then((res) => res.data.data) authApi(apiUrl(ApiEndpoints.auth_providers)).then((res) => res.data.data)
}); });
useEffect(() => { useEffect(() => {
if (auth_settings === undefined) return; if (auth_config === undefined) return;
if (data === undefined) return; if (data === undefined) return;
const configuredProviders = data.map((item: any) => { const configuredProviders = data.map((item: any) => {
@ -220,16 +222,15 @@ function SsoContent({
} }
// remove providers that are used currently // remove providers that are used currently
const newData = const newData = auth_config.socialaccount.providers.filter(isAlreadyInUse);
auth_settings.socialaccount.providers.filter(isAlreadyInUse);
setCurrentProviders(newData); setCurrentProviders(newData);
}, [auth_settings, data]); }, [auth_config, data]);
function removeProvider() { function removeProvider() {
const split = value.split('$'); const split = value.split('$');
const provider = split[split.length - 1]; const provider = split[split.length - 1];
const uid = split.slice(0, split.length - 1).join('$'); const uid = split.slice(0, split.length - 1).join('$');
authApi(apiUrl(ApiEndpoints.user_sso), undefined, 'delete', { authApi(apiUrl(ApiEndpoints.auth_providers), undefined, 'delete', {
provider: provider, provider: provider,
account: uid account: uid
}) })
@ -303,7 +304,9 @@ function MfaContent() {
const { isLoading, data, refetch } = useQuery({ const { isLoading, data, refetch } = useQuery({
queryKey: ['mfa-list'], queryKey: ['mfa-list'],
queryFn: () => queryFn: () =>
api.get(apiUrl(ApiEndpoints.user_mfa)).then((res) => res.data.data) api
.get(apiUrl(ApiEndpoints.auth_authenticators))
.then((res) => res.data.data)
}); });
function parseDate(date: number) { function parseDate(date: number) {

View File

@ -4,13 +4,13 @@ import { createJSONStorage, persist } from 'zustand/middleware';
import { api } from '../App'; import { api } from '../App';
import { emptyServerAPI } from '../defaults/defaults'; import { emptyServerAPI } from '../defaults/defaults';
import { ApiEndpoints } from '../enums/ApiEndpoints'; import { ApiEndpoints } from '../enums/ApiEndpoints';
import type { SecuritySetting, ServerAPIProps } from './states'; import type { AuthConfig, ServerAPIProps } from './states';
interface ServerApiStateProps { interface ServerApiStateProps {
server: ServerAPIProps; server: ServerAPIProps;
setServer: (newServer: ServerAPIProps) => void; setServer: (newServer: ServerAPIProps) => void;
fetchServerApiState: () => void; fetchServerApiState: () => void;
auth_settings?: SecuritySetting; auth_config?: AuthConfig;
sso_enabled: () => boolean; sso_enabled: () => boolean;
mfa_enabled: () => boolean; mfa_enabled: () => boolean;
registration_enabled: () => boolean; registration_enabled: () => boolean;
@ -37,19 +37,19 @@ export const useServerApiState = create<ServerApiStateProps>()(
// Fetch login/SSO behaviour // Fetch login/SSO behaviour
await api await api
.get(apiUrl(ApiEndpoints.securtiy_settings), { .get(apiUrl(ApiEndpoints.auth_config), {
headers: { Authorization: '' } headers: { Authorization: '' }
}) })
.then((response) => { .then((response) => {
set({ auth_settings: response.data.data }); set({ auth_config: response.data.data });
}) })
.catch(() => { .catch(() => {
console.error('ERR: Error fetching SSO information'); console.error('ERR: Error fetching SSO information');
}); });
}, },
auth_settings: undefined, auth_config: undefined,
sso_enabled: () => { sso_enabled: () => {
const data = get().auth_settings?.socialaccount.providers; const data = get().auth_config?.socialaccount.providers;
return !(data === undefined || data.length == 0); return !(data === undefined || data.length == 0);
}, },
mfa_enabled: () => { mfa_enabled: () => {

View File

@ -50,7 +50,7 @@ export interface ServerAPIProps {
django_admin: null | string; django_admin: null | string;
} }
export interface SecuritySetting { export interface AuthConfig {
account: { account: {
authentication_method: string; authentication_method: string;
}; };