Skip to content

Commit 5c3d00c

Browse files
committed
#795 Send auth as Authorization header
1 parent f8c09c1 commit 5c3d00c

3 files changed

Lines changed: 18 additions & 9 deletions

File tree

.github/workflows/task-deadline-notifications.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ jobs:
1010
steps:
1111
- name: Send notifications
1212
run: |
13-
curl -X POST https://api.finishlinebyner.com/tasks/sendTaskDeadlineSlackNotifications \
14-
-H 'Content-Type: application/json' \
15-
-d '{
16-
"token": "${{ secrets.NOTIFICATION_ENDPOINT_SECRET }}"
17-
}'
13+
curl -X GET https://api.finishlinebyner.com/tasks/sendTaskDeadlineSlackNotifications \
14+
-H 'Authorization: ${{ secrets.NOTIFICATION_ENDPOINT_SECRET }}'

src/backend/src/routes/tasks.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ tasksRouter.post(
3838

3939
tasksRouter.post('/:taskId/delete', TasksController.deleteTask);
4040

41-
tasksRouter.post('/sendTaskDeadlineSlackNotifications', TasksController.sendTaskDeadlineSlackNotifications);
41+
tasksRouter.get('/sendTaskDeadlineSlackNotifications', TasksController.sendTaskDeadlineSlackNotifications);
4242

4343
export default tasksRouter;

src/backend/src/utils/auth.utils.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export const requireJwtProd = (req: Request, res: Response, next: NextFunction)
3535
} else if (
3636
req.path === '/tasks/sendTaskDeadlineSlackNotifications' // task deadline notification endpoint
3737
) {
38-
const { secret } = req.body;
38+
const { authorization } = req.headers;
3939
const { NOTIFICATION_ENDPOINT_SECRET } = process.env;
4040

41-
if (!secret) return res.status(401).json({ message: 'Authentication Failed: Secret not found!' });
41+
if (!authorization) return res.status(401).json({ message: 'Authentication Failed: Secret not found!' });
4242

43-
if (secret !== NOTIFICATION_ENDPOINT_SECRET)
43+
if (authorization !== NOTIFICATION_ENDPOINT_SECRET)
4444
return res.status(401).json({ message: 'Authentication Failed: Invalid secret!' });
4545

4646
next();
@@ -70,6 +70,18 @@ export const requireJwtDev = (req: Request, res: Response, next: NextFunction) =
7070
req.method === 'OPTIONS' || // this is a pre-flight request and those don't send cookies
7171
req.path === '/users' // dev login needs the list of users to log in
7272
) {
73+
next();
74+
} else if (
75+
req.path === '/tasks/sendTaskDeadlineSlackNotifications' // task deadline notification endpoint
76+
) {
77+
const { authorization } = req.headers;
78+
const { NOTIFICATION_ENDPOINT_SECRET } = process.env;
79+
80+
if (!authorization) return res.status(401).json({ message: 'Authentication Failed: Secret not found!' });
81+
82+
if (authorization !== NOTIFICATION_ENDPOINT_SECRET)
83+
return res.status(401).json({ message: 'Authentication Failed: Invalid secret!' });
84+
7385
next();
7486
} else {
7587
const devUserId = req.headers.authorization;

0 commit comments

Comments
 (0)