mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
align names with allauth
This commit is contained in:
@ -35,9 +35,9 @@ export function AuthenticationForm() {
|
||||
});
|
||||
const simpleForm = useForm({ initialValues: { email: '' } });
|
||||
const [classicLoginMode, setMode] = useDisclosure(true);
|
||||
const [auth_settings, sso_enabled, password_forgotten_enabled] =
|
||||
const [auth_config, sso_enabled, password_forgotten_enabled] =
|
||||
useServerApiState((state) => [
|
||||
state.auth_settings,
|
||||
state.auth_config,
|
||||
state.sso_enabled,
|
||||
state.password_forgotten_enabled
|
||||
]);
|
||||
@ -107,7 +107,7 @@ export function AuthenticationForm() {
|
||||
{sso_enabled() ? (
|
||||
<>
|
||||
<Group grow mb='md' mt='md'>
|
||||
{auth_settings?.socialaccount.providers.map((provider) => (
|
||||
{auth_config?.socialaccount.providers.map((provider) => (
|
||||
<SsoButton provider={provider} key={provider.id} />
|
||||
))}
|
||||
</Group>
|
||||
@ -205,9 +205,9 @@ export function RegistrationForm() {
|
||||
}
|
||||
});
|
||||
const navigate = useNavigate();
|
||||
const [auth_settings, registration_enabled, sso_registration] =
|
||||
const [auth_config, registration_enabled, sso_registration] =
|
||||
useServerApiState((state) => [
|
||||
state.auth_settings,
|
||||
state.auth_config,
|
||||
state.registration_enabled,
|
||||
state.sso_registration_enabled
|
||||
]);
|
||||
@ -228,7 +228,7 @@ export function RegistrationForm() {
|
||||
await ensureCsrf();
|
||||
|
||||
api
|
||||
.post(apiUrl(ApiEndpoints.user_register), vals, {
|
||||
.post(apiUrl(ApiEndpoints.auth_signup), vals, {
|
||||
headers: { Authorization: '' }
|
||||
})
|
||||
.then((ret) => {
|
||||
@ -321,7 +321,7 @@ export function RegistrationForm() {
|
||||
)}
|
||||
{sso_registration() && (
|
||||
<Group grow mb='md' mt='md'>
|
||||
{auth_settings?.socialaccount.providers.map((provider) => (
|
||||
{auth_config?.socialaccount.providers.map((provider) => (
|
||||
<SsoButton provider={provider} key={provider.id} />
|
||||
))}
|
||||
</Group>
|
||||
|
@ -18,15 +18,16 @@ export enum ApiEndpoints {
|
||||
user_simple_login = 'email/generate/',
|
||||
user_reset = 'auth/password/reset/', // TODO change
|
||||
user_reset_set = 'auth/password/reset/confirm/', // TODO change
|
||||
user_change_password = 'auth/v1/account/password/change',
|
||||
user_sso = 'auth/v1/account/providers',
|
||||
user_login = 'auth/v1/auth/login',
|
||||
user_login_mfa = 'auth/v1/auth/2fa/authenticate',
|
||||
user_logout = 'auth/v1/auth/session',
|
||||
user_register = 'auth/v1/auth/signup',
|
||||
user_mfa = 'auth/v1/account/authenticators',
|
||||
user_emails = 'auth/v1/account/email',
|
||||
login_provider_redirect = 'auth/v1/auth/provider/redirect',
|
||||
auth_pwd_change = 'auth/v1/account/password/change',
|
||||
auth_login = 'auth/v1/auth/login',
|
||||
auth_login_2fa = 'auth/v1/auth/2fa/authenticate',
|
||||
auth_session = 'auth/v1/auth/session',
|
||||
auth_signup = 'auth/v1/auth/signup',
|
||||
auth_authenticators = 'auth/v1/account/authenticators',
|
||||
auth_email = 'auth/v1/account/email',
|
||||
auth_providers = 'auth/v1/account/providers',
|
||||
auth_provider_redirect = 'auth/v1/auth/provider/redirect',
|
||||
auth_config = 'auth/v1/config',
|
||||
|
||||
// Generic API endpoints
|
||||
currency_list = 'currency/exchange/',
|
||||
@ -50,7 +51,6 @@ export enum ApiEndpoints {
|
||||
icons = 'icons/',
|
||||
selectionlist_list = 'selection/',
|
||||
selectionlist_detail = 'selection/:id/',
|
||||
securtiy_settings = 'auth/v1/config',
|
||||
|
||||
// Barcode API endpoints
|
||||
barcode = 'barcode/',
|
||||
|
@ -74,7 +74,7 @@ export const doBasicLogin = async (
|
||||
clearCsrfCookie();
|
||||
await ensureCsrf();
|
||||
|
||||
const login_url = apiUrl(ApiEndpoints.user_login);
|
||||
const login_url = apiUrl(ApiEndpoints.auth_login);
|
||||
|
||||
let loginDone = false;
|
||||
let success = false;
|
||||
@ -129,7 +129,7 @@ export const doLogout = async (navigate: NavigateFunction) => {
|
||||
|
||||
// Logout from the server session
|
||||
if (isLoggedIn() || !!getCsrfCookie()) {
|
||||
await authApi(apiUrl(ApiEndpoints.user_logout), undefined, 'delete').catch(
|
||||
await authApi(apiUrl(ApiEndpoints.auth_session), undefined, 'delete').catch(
|
||||
() => {}
|
||||
);
|
||||
showLoginNotification({
|
||||
@ -203,7 +203,7 @@ export function handleMfaLogin(
|
||||
values: { code: string }
|
||||
) {
|
||||
const { setToken } = useUserState.getState();
|
||||
authApi(apiUrl(ApiEndpoints.user_login_mfa), undefined, 'post', {
|
||||
authApi(apiUrl(ApiEndpoints.auth_login_2fa), undefined, 'post', {
|
||||
code: values.code
|
||||
}).then((response) => {
|
||||
setToken(response.data.meta.access_token);
|
||||
@ -300,7 +300,7 @@ export function ProviderLogin(
|
||||
process: process,
|
||||
csrfmiddlewaretoken: getCsrfCookie()
|
||||
};
|
||||
const url = `${host}${apiUrl(ApiEndpoints.login_provider_redirect)}`;
|
||||
const url = `${host}${apiUrl(ApiEndpoints.auth_provider_redirect)}`;
|
||||
post(url, values);
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ export default function Set_Password() {
|
||||
|
||||
// Set password with call to backend
|
||||
api
|
||||
.post(apiUrl(ApiEndpoints.user_change_password), {
|
||||
.post(apiUrl(ApiEndpoints.auth_pwd_change), {
|
||||
current_password: simpleForm.values.current_password,
|
||||
new_password: simpleForm.values.new_password2
|
||||
})
|
||||
|
@ -22,12 +22,14 @@ import { YesNoButton } from '../../../../components/buttons/YesNoButton';
|
||||
import { ApiEndpoints } from '../../../../enums/ApiEndpoints';
|
||||
import { ProviderLogin, authApi } from '../../../../functions/auth';
|
||||
import { apiUrl, useServerApiState } from '../../../../states/ApiState';
|
||||
import type { Provider, SecuritySetting } from '../../../../states/states';
|
||||
import type { AuthConfig, Provider } from '../../../../states/states';
|
||||
|
||||
export function SecurityContent() {
|
||||
const [auth_settings, sso_enabled, mfa_enabled] = useServerApiState(
|
||||
(state) => [state.auth_settings, state.sso_enabled, state.mfa_enabled]
|
||||
);
|
||||
const [auth_config, sso_enabled, mfa_enabled] = useServerApiState((state) => [
|
||||
state.auth_config,
|
||||
state.sso_enabled,
|
||||
state.mfa_enabled
|
||||
]);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
@ -39,7 +41,7 @@ export function SecurityContent() {
|
||||
<Trans>Single Sign On Accounts</Trans>
|
||||
</Title>
|
||||
{sso_enabled() ? (
|
||||
<SsoContent auth_settings={auth_settings} />
|
||||
<SsoContent auth_config={auth_config} />
|
||||
) : (
|
||||
<Alert
|
||||
icon={<IconAlertCircle size='1rem' />}
|
||||
@ -81,7 +83,7 @@ function EmailContent() {
|
||||
const { isLoading, data, refetch } = useQuery({
|
||||
queryKey: ['emails'],
|
||||
queryFn: () =>
|
||||
authApi(apiUrl(ApiEndpoints.user_emails)).then((res) => res.data.data)
|
||||
authApi(apiUrl(ApiEndpoints.auth_email)).then((res) => res.data.data)
|
||||
});
|
||||
|
||||
function runServerAction(
|
||||
@ -90,7 +92,7 @@ function EmailContent() {
|
||||
) {
|
||||
const vals: any = data || { email: value };
|
||||
console.log('vals', vals);
|
||||
authApi(apiUrl(ApiEndpoints.user_emails), undefined, action, vals)
|
||||
authApi(apiUrl(ApiEndpoints.auth_email), undefined, action, vals)
|
||||
.then(() => {
|
||||
refetch();
|
||||
})
|
||||
@ -198,18 +200,18 @@ function ProviderButton({ provider }: Readonly<{ provider: Provider }>) {
|
||||
}
|
||||
|
||||
function SsoContent({
|
||||
auth_settings
|
||||
}: Readonly<{ auth_settings: SecuritySetting | undefined }>) {
|
||||
auth_config
|
||||
}: Readonly<{ auth_config: AuthConfig | undefined }>) {
|
||||
const [value, setValue] = useState<string>('');
|
||||
const [currentProviders, setCurrentProviders] = useState<Provider[]>();
|
||||
const { isLoading, data, refetch } = useQuery({
|
||||
queryKey: ['sso-list'],
|
||||
queryFn: () =>
|
||||
authApi(apiUrl(ApiEndpoints.user_sso)).then((res) => res.data.data)
|
||||
authApi(apiUrl(ApiEndpoints.auth_providers)).then((res) => res.data.data)
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (auth_settings === undefined) return;
|
||||
if (auth_config === undefined) return;
|
||||
if (data === undefined) return;
|
||||
|
||||
const configuredProviders = data.map((item: any) => {
|
||||
@ -220,16 +222,15 @@ function SsoContent({
|
||||
}
|
||||
|
||||
// remove providers that are used currently
|
||||
const newData =
|
||||
auth_settings.socialaccount.providers.filter(isAlreadyInUse);
|
||||
const newData = auth_config.socialaccount.providers.filter(isAlreadyInUse);
|
||||
setCurrentProviders(newData);
|
||||
}, [auth_settings, data]);
|
||||
}, [auth_config, data]);
|
||||
|
||||
function removeProvider() {
|
||||
const split = value.split('$');
|
||||
const provider = split[split.length - 1];
|
||||
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,
|
||||
account: uid
|
||||
})
|
||||
@ -303,7 +304,9 @@ function MfaContent() {
|
||||
const { isLoading, data, refetch } = useQuery({
|
||||
queryKey: ['mfa-list'],
|
||||
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) {
|
||||
|
@ -4,13 +4,13 @@ import { createJSONStorage, persist } from 'zustand/middleware';
|
||||
import { api } from '../App';
|
||||
import { emptyServerAPI } from '../defaults/defaults';
|
||||
import { ApiEndpoints } from '../enums/ApiEndpoints';
|
||||
import type { SecuritySetting, ServerAPIProps } from './states';
|
||||
import type { AuthConfig, ServerAPIProps } from './states';
|
||||
|
||||
interface ServerApiStateProps {
|
||||
server: ServerAPIProps;
|
||||
setServer: (newServer: ServerAPIProps) => void;
|
||||
fetchServerApiState: () => void;
|
||||
auth_settings?: SecuritySetting;
|
||||
auth_config?: AuthConfig;
|
||||
sso_enabled: () => boolean;
|
||||
mfa_enabled: () => boolean;
|
||||
registration_enabled: () => boolean;
|
||||
@ -37,19 +37,19 @@ export const useServerApiState = create<ServerApiStateProps>()(
|
||||
|
||||
// Fetch login/SSO behaviour
|
||||
await api
|
||||
.get(apiUrl(ApiEndpoints.securtiy_settings), {
|
||||
.get(apiUrl(ApiEndpoints.auth_config), {
|
||||
headers: { Authorization: '' }
|
||||
})
|
||||
.then((response) => {
|
||||
set({ auth_settings: response.data.data });
|
||||
set({ auth_config: response.data.data });
|
||||
})
|
||||
.catch(() => {
|
||||
console.error('ERR: Error fetching SSO information');
|
||||
});
|
||||
},
|
||||
auth_settings: undefined,
|
||||
auth_config: undefined,
|
||||
sso_enabled: () => {
|
||||
const data = get().auth_settings?.socialaccount.providers;
|
||||
const data = get().auth_config?.socialaccount.providers;
|
||||
return !(data === undefined || data.length == 0);
|
||||
},
|
||||
mfa_enabled: () => {
|
||||
|
@ -50,7 +50,7 @@ export interface ServerAPIProps {
|
||||
django_admin: null | string;
|
||||
}
|
||||
|
||||
export interface SecuritySetting {
|
||||
export interface AuthConfig {
|
||||
account: {
|
||||
authentication_method: string;
|
||||
};
|
||||
|
Reference in New Issue
Block a user