Skip to content

Commit 65ff1ca

Browse files
authored
Oauth2 (#385)
* basic oauth setup * automatic registration for Oauth2 users * more refactoring and adding support for oauth2 * frontend to handle oauth2 signin * Oauth2Handler handles returning secure Cookie to frontend and redirect After a successful oauth2 should have either created a new user or found an existing user. * AuthService is handling more of the Oauth chain of events * Remove default form login * Add user-info endpoint * Usermangement now supports user-info * endpoint to get registration info * UserController to have null checks for Oauth2 * remove commented out code * safe guards for incomplete client registrations * formatting * clean up conditional code to separate functions * props * update moduleResolution to bundler to resolve import error for import functionality
1 parent b893e18 commit 65ff1ca

File tree

20 files changed

+1276
-1040
lines changed

20 files changed

+1276
-1040
lines changed

frontend/api/Api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ instance.interceptors.response.use(
4545
},
4646
);
4747

48-
function parseData(data: string) {
48+
export function parseData(data: string) {
4949
if (data.length != 0 || data || data != "") {
5050
return JSON.parse(data);
5151
}

frontend/api/userApi.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import axios from "axios";
2+
import { parseData } from "./Api";
3+
const SERVER_URL = process.env.NEXT_PUBLIC_SERVER_URL + "/user";
4+
5+
export const instance = axios.create({
6+
withCredentials: true,
7+
baseURL: SERVER_URL,
8+
timeout: 10000,
9+
transformResponse: [
10+
function (data: any) {
11+
return parseData(data);
12+
},
13+
],
14+
});
15+
16+
const userApi = {
17+
async execute(
18+
method: string,
19+
resource: string,
20+
data: any,
21+
config: {} | undefined,
22+
) {
23+
return instance({
24+
method: method,
25+
url: resource,
26+
data,
27+
...config,
28+
});
29+
},
30+
userInfo() {
31+
return instance.get("/user-info")
32+
}
33+
}
34+
35+
export default userApi;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use client";
2+
/**
3+
* Once a user logins with OAuth2 from backend service
4+
* they should be brought here. This will quickly read
5+
* the call authService which will make a request to
6+
* the endpoint /user-info with the already attached
7+
* cookie and save the User info.
8+
*/
9+
import authService from "@/services/auth.service";
10+
import { useRouter } from "next/navigation";
11+
import { useEffect } from "react";
12+
13+
export default function OauthLogin() {
14+
const router = useRouter();
15+
16+
useEffect(() => {
17+
authService.getUserInfoOauth2().then((user) => {
18+
if (user) {
19+
router.push("/");
20+
}
21+
})
22+
}, [authService])
23+
24+
}

frontend/components/Import/FilePicker.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export default function FilePicker({ setUpload, setFile }: FilePickerProps) {
3939
return <div>Error...</div>;
4040
}
4141
return (
42-
<button className="btn btn-outline-info" onClick={() => openFilePicker()} title = "Import Bookmarks">
42+
<button
43+
className="btn btn-outline-info"
44+
onClick={() => openFilePicker()}
45+
title="Import Bookmarks"
46+
>
4347
<i className="bi bi-arrow-bar-up"> Upload File</i>
4448
</button>
4549
);

frontend/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@
2424
"autoprefixer": "10.4.20",
2525
"axios": "^1.9.0",
2626
"axios-mock-adapter": "^2.1.0",
27-
"bootstrap": "^5.3.5",
28-
"bootstrap-icons": "^1.11.3",
27+
"bootstrap": "^5.3.6",
28+
"bootstrap-icons": "^1.13.1",
2929
"dotenv": "^16.5.0",
3030
"eslint": "9.17.0",
3131
"eslint-config-next": "15.1.3",
3232
"formik": "^2.4.6",
3333
"jest": "^29.7.0",
34-
"next": "^15.3.1",
34+
"next": "^15.3.3",
3535
"next-router-mock": "^0.9.13",
36-
"postcss": "^8.5.3",
36+
"postcss": "^8.5.4",
3737
"react": "19.0.0",
38-
"react-bootstrap": "^2.10.9",
38+
"react-bootstrap": "^2.10.10",
3939
"react-dom": "19.0.0",
4040
"react-toastify": "^11.0.5",
4141
"rxjs": "^7.8.2",
42-
"sass": "^1.87.0",
42+
"sass": "^1.89.2",
4343
"tailwindcss": "3.4.17",
4444
"typescript": "5.7.2",
45-
"use-file-picker": "^2.1.2",
45+
"use-file-picker": "^2.1.4",
4646
"vite-tsconfig-paths": "^5.1.4",
4747
"vitest-preview": "^0.0.1",
4848
"yup": "^1.6.1"
@@ -52,12 +52,12 @@
5252
"@testing-library/jest-dom": "^6.6.3",
5353
"@testing-library/react": "^16.3.0",
5454
"@testing-library/user-event": "^14.6.1",
55-
"@vitejs/plugin-react": "^4.4.1",
56-
"@vitest/coverage-v8": "^3.1.2",
57-
"@vitest/ui": "^3.1.2",
55+
"@vitejs/plugin-react": "^4.5.2",
56+
"@vitest/coverage-v8": "^3.2.3",
57+
"@vitest/ui": "^3.2.3",
5858
"jsdom": "^25.0.1",
59-
"testcontainers": "^10.24.2",
60-
"vitest": "^3.1.2"
59+
"testcontainers": "^10.28.0",
60+
"vitest": "^3.2.3"
6161
},
6262
"pnpm": {
6363
"overrides": {

0 commit comments

Comments
 (0)