Skip to content

Commit

Permalink
Added Auth for Identity Service (#200)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lakshayman authored Feb 21, 2024
1 parent 435c939 commit c5ad7bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/controllers/profileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { env } from "../typeDefinitions/default.types";
import { sendProfileServiceBlockedMessage } from "../utils/sendProfileServiceBlockedMessage";
import JSONResponse from "../utils/JsonResponse";
import * as response from "../constants/responses";
import { verifyNodejsBackendAuthToken } from "../utils/verifyAuthToken";
import { verifyIdentityServiceAuthToken } from "../utils/verifyAuthToken";

export const sendProfileBlockedMessage = async (request: any, env: env) => {
const authHeader = request.headers.get("Authorization");
if (!authHeader) {
return new JSONResponse(response.BAD_SIGNATURE);
}
try {
await verifyNodejsBackendAuthToken(authHeader, env);
await verifyIdentityServiceAuthToken(authHeader, env);
const messageRequest: { userId: string; reason: string } =
await request.json();
const { userId, reason } = messageRequest;
Expand Down
17 changes: 17 additions & 0 deletions src/utils/verifyAuthToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ export async function verifyNodejsBackendAuthToken(
}
}

/**
*
* @param authHeader { string } : the auth header of request
* @param env { env }: the ctx (context) which contains the secrets put in as wrangler secrets.
*/

export async function verifyIdentityServiceAuthToken(
authHeader: string,
env: env
) {
try {
await verifyAuthToken(authHeader, env.IDENTITY_SERVICE_PUBLIC_KEY);
} catch (err: any) {
throw new Error(err.message);
}
}

/**
*
* @param authHeader { string } : the auth header of request
Expand Down

0 comments on commit c5ad7bf

Please sign in to comment.