Adds LDAP auth support

This commit is contained in:
Jamie Curnow
2024-11-02 21:36:07 +10:00
parent 8434a2d1fa
commit a277a5d167
54 changed files with 765 additions and 306 deletions

View File

@ -3,7 +3,7 @@
"version": "3.0.0",
"private": true,
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:ci": "yarn lint --watchAll=false",

View File

@ -6,7 +6,7 @@ export async function getSSEToken(
): Promise<TokenResponse> {
const { result } = await api.post(
{
url: "/tokens/sse",
url: "/auth/sse",
},
abortController,
);

View File

@ -15,7 +15,7 @@ export async function getToken(
): Promise<TokenResponse> {
const { result } = await api.post(
{
url: "/tokens",
url: "/auth",
data: payload,
},
abortController,

View File

@ -4,9 +4,9 @@ import { TokenResponse } from "./responseTypes";
export async function refreshToken(
abortController?: AbortController,
): Promise<TokenResponse> {
const { result } = await api.get(
const { result } = await api.post(
{
url: "/tokens",
url: "/auth/refresh",
},
abortController,
);

View File

@ -1,4 +1,4 @@
import { ReactNode, createContext, useContext, useState } from "react";
import { createContext, ReactNode, useContext, useState } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { useIntervalWhen } from "rooks";
@ -9,7 +9,7 @@ import AuthStore from "src/modules/AuthStore";
// Context
export interface AuthContextType {
authenticated: boolean;
login: (username: string, password: string) => Promise<void>;
login: (type: string, username: string, password: string) => Promise<void>;
logout: () => void;
token?: string;
}
@ -36,8 +36,7 @@ function AuthProvider({
setAuthenticated(true);
};
const login = async (identity: string, secret: string) => {
const type = "password";
const login = async (type: string, identity: string, secret: string) => {
const response = await getToken({ payload: { type, identity, secret } });
handleTokenUpdate(response);
};

View File

@ -5,16 +5,16 @@ import {
FormLabel,
Input,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Stack,
useToast,
} from "@chakra-ui/react";
import { Formik, Form, Field } from "formik";
import { Field, Form, Formik } from "formik";
import { setAuth } from "src/api/npm";
import { PrettyButton } from "src/components";
@ -43,7 +43,7 @@ function ChangePasswordModal({ isOpen, onClose }: ChangePasswordModalProps) {
try {
await setAuth("me", {
type: "password",
type: "local",
secret: payload.password,
currentSecret: payload.current,
});

View File

@ -5,16 +5,16 @@ import {
FormLabel,
Input,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Stack,
useToast,
} from "@chakra-ui/react";
import { Formik, Form, Field } from "formik";
import { Field, Form, Formik } from "formik";
import { setAuth } from "src/api/npm";
import { PrettyButton } from "src/components";
@ -44,7 +44,7 @@ function SetPasswordModal({ userId, isOpen, onClose }: SetPasswordModalProps) {
try {
await setAuth(userId, {
type: "password",
type: "local",
secret: payload.password,
});
onClose();

View File

@ -7,22 +7,22 @@ import {
FormLabel,
Input,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalCloseButton,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Stack,
Tab,
Tabs,
TabList,
TabPanel,
TabPanels,
Tabs,
useToast,
} from "@chakra-ui/react";
import { useQueryClient } from "@tanstack/react-query";
import { Formik, Form, Field } from "formik";
import { Field, Form, Formik } from "formik";
import { createUser } from "src/api/npm";
import {
@ -56,7 +56,7 @@ function UserCreateModal({ isOpen, onClose }: UserCreateModalProps) {
...{
isDisabled: false,
auth: {
type: "password",
type: "local",
secret: values.password,
},
capabilities,

View File

@ -1,9 +1,9 @@
import { useEffect, useRef } from "react";
import {
Box,
Center,
Flex,
Box,
FormControl,
FormErrorMessage,
FormLabel,
@ -12,7 +12,7 @@ import {
useColorModeValue,
useToast,
} from "@chakra-ui/react";
import { Formik, Form, Field } from "formik";
import { Field, Form, Formik } from "formik";
import { LocalePicker, PrettyButton, ThemeSwitcher } from "src/components";
import { useAuthState } from "src/context";
@ -40,7 +40,7 @@ function Login() {
};
try {
await login(values.email, values.password);
await login("local", values.email, values.password);
} catch (err) {
if (err instanceof Error) {
showErr(err.message);

View File

@ -7,14 +7,14 @@ import {
FormControl,
FormErrorMessage,
FormLabel,
Stack,
Heading,
Input,
Stack,
useColorModeValue,
useToast,
} from "@chakra-ui/react";
import { useQueryClient } from "@tanstack/react-query";
import { Formik, Form, Field } from "formik";
import { Field, Form, Formik } from "formik";
import { createUser } from "src/api/npm";
// import logo from "src/assets/logo-256.png";
@ -42,7 +42,7 @@ function Setup() {
...{
isDisabled: false,
auth: {
type: "password",
type: "local",
secret: values.password,
},
capabilities: ["full-admin"],
@ -65,7 +65,7 @@ function Setup() {
const response = await createUser(payload);
if (response && typeof response.id !== "undefined" && response.id) {
try {
await login(response.email, password);
await login("local", response.email, password);
// Trigger a Health change
await queryClient.refetchQueries({ queryKey: ["health"] });
// window.location.reload();