Skip to content

Commit a724484

Browse files
author
Conner Hnatiuk
committed
Authentication is working, only when run on the vm though. Error in admin-router, setting headers too late.
1 parent 13f2eb5 commit a724484

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

server/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async function initializeSystem(): Promise<DatabaseController> {
4444
initializeSystem().then((dbController: DatabaseController) => {
4545
app.use("/", exampleRouter);
4646
//app.use("/getTable", tableRouter)
47-
app.use("/dataRequest", cascadeRouter(dbController));
48-
app.use("/adminRequest", adminRouter(dbController));
47+
app.use("/api/dataRequest", cascadeRouter(dbController));
48+
app.use("/api/adminRequest", adminRouter(dbController));
4949

5050
app.listen(PORT, () => {
5151
console.log(`Server is running on ${PORT}`);

server/src/routes/admin-router.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,29 @@ export default function adminRouter(dbController: DatabaseController): Router {
5555
router.get("/auth/cas-validate", async (req: Request, res: Response) => {
5656
const { ticket, service } = req.query;
5757

58+
console.log("hit");
59+
console.log(ticket);
60+
console.log(service);
5861
if (!ticket || !service) {
5962
res.status(400).json({ error: "Missing ticket or service" });
6063
}
6164

6265
try {
6366
// Validate CAS ticket
6467
const casResponse = await axios.get(
65-
`https://cas.usask.ca/serviceValidate`,
68+
`https://cas.usask.ca/cas/serviceValidate`,
6669
{
6770
params: { ticket, service },
6871
},
6972
);
7073

74+
75+
7176
const casData = casResponse.data; // assumed user CAS info, need to test to see
7277
const nsid = casData.user; // Potentally the nsid of the user. Again need to test
7378

79+
console.log(casData);
80+
console.log(nsid);
7481
if (!nsid) {
7582
res.status(401).json({ error: "Invalid CAS Ticket" });
7683
}

web/src/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ function App() {
1515
<Routes>
1616
{/* Unprotected routes */}
1717
<Route path="/cas-callback" element={<CASCallback />} />
18-
18+
19+
<Route
20+
path="/"
21+
element={
22+
<ProtectedRoute>
23+
<div>Hello</div>
24+
</ProtectedRoute>
25+
}
26+
></Route>
1927
{/* Protected Routes */}
2028
<Route
2129
path="/upload"

web/src/auth/CASCallback.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import React, { useEffect } from 'react';
22

3-
const BACKEND_URL = 'https://starr-lab-server.usask.ca/api'; // Replace with your backend URL
3+
const BACKEND_URL = 'https://starr-lab-server.usask.ca'; // Replace with your backend URL
44

55
const CASCallback: React.FC = () => {
66
useEffect(() => {
77
// Extract CAS ticket from URL
88
const urlParams = new URLSearchParams(window.location.search);
99
const ticket = urlParams.get('ticket');
1010

11+
console.log(ticket);
12+
1113
if (ticket) {
1214
// Call backend to validate ticket
13-
fetch(`${BACKEND_URL}/admin-router/auth/cas-validate?ticket=${ticket}&service=${encodeURIComponent(window.location.origin + '/cas-callback')}`)
15+
fetch(`${BACKEND_URL}/api/adminRequest/auth/cas-validate?ticket=${ticket}&service=${encodeURIComponent(window.location.origin + '/cas-callback')}`)
1416
.then((response) => response.json())
1517
.then((data) => {
1618
if (data.token) {

web/src/auth/ProtectedRoute.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function redirectToCAS() {
22
const CAS_SERVER = "https://cas.usask.ca/cas";
3-
const FRONTEND_URL = "https://starr-lab-server.usask.ca:5173/";
3+
const FRONTEND_URL = "https://starr-lab-server.usask.ca";
44
const serviceURL = `${FRONTEND_URL}/cas-callback`;
55

66
window.location.href = `${CAS_SERVER}/login?service=${encodeURIComponent(

0 commit comments

Comments
 (0)