Skip to content

Commit c5ad7bf

Browse files
authored
Added Auth for Identity Service (#200)
* Added a route to sent Profile Blocked Messages * Modification to the message bot is sending * Authentication Added * Fixed Lint issues * Code Cleaning * Update variables.ts * Code Cleaning * Added a re-usable function for auth token * Added Auth for Identity Service
1 parent 435c939 commit c5ad7bf

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/controllers/profileHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { env } from "../typeDefinitions/default.types";
22
import { sendProfileServiceBlockedMessage } from "../utils/sendProfileServiceBlockedMessage";
33
import JSONResponse from "../utils/JsonResponse";
44
import * as response from "../constants/responses";
5-
import { verifyNodejsBackendAuthToken } from "../utils/verifyAuthToken";
5+
import { verifyIdentityServiceAuthToken } from "../utils/verifyAuthToken";
66

77
export const sendProfileBlockedMessage = async (request: any, env: env) => {
88
const authHeader = request.headers.get("Authorization");
99
if (!authHeader) {
1010
return new JSONResponse(response.BAD_SIGNATURE);
1111
}
1212
try {
13-
await verifyNodejsBackendAuthToken(authHeader, env);
13+
await verifyIdentityServiceAuthToken(authHeader, env);
1414
const messageRequest: { userId: string; reason: string } =
1515
await request.json();
1616
const { userId, reason } = messageRequest;

src/utils/verifyAuthToken.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ export async function verifyNodejsBackendAuthToken(
3939
}
4040
}
4141

42+
/**
43+
*
44+
* @param authHeader { string } : the auth header of request
45+
* @param env { env }: the ctx (context) which contains the secrets put in as wrangler secrets.
46+
*/
47+
48+
export async function verifyIdentityServiceAuthToken(
49+
authHeader: string,
50+
env: env
51+
) {
52+
try {
53+
await verifyAuthToken(authHeader, env.IDENTITY_SERVICE_PUBLIC_KEY);
54+
} catch (err: any) {
55+
throw new Error(err.message);
56+
}
57+
}
58+
4259
/**
4360
*
4461
* @param authHeader { string } : the auth header of request

0 commit comments

Comments
 (0)