Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Auth for Identity Service #200

Merged
merged 12 commits into from
Feb 21, 2024
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
Loading