Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Tweaks to utils/hooks.ts
Browse files Browse the repository at this point in the history
Signed-off-by: Emiliano Suñé <emiliano.sune@gmail.com>
  • Loading branch information
esune committed Nov 4, 2020
1 parent cff5dba commit cd09934
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions api/src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ export async function canDeleteInvite(context: HookContext) {
}

export async function verifyJWT(context: HookContext) {
const authHeader = context.params.headers?.authorization as string;
if (!authHeader) {
return Promise.reject(new Forbidden("The authorization header is missing"));
const token = extractIdToken(
context.params.headers?.authorization as string
);
if (!token) {
throw new Forbidden("The authorization header is missing");
}
const token = authHeader.split(" ")[1];
const keys = await getAuthSigningKeys(context);
decodeIdToken(token, keys, context);
verifyIdToken(token, keys, context);
return context;
}

Expand Down Expand Up @@ -99,7 +100,7 @@ export async function validateCredentialRequest(context: HookContext) {
);
const keys = await getAuthSigningKeys(context);

const decoded = decodeIdToken(idToken, keys, context);
const decoded = verifyIdToken(idToken, keys, context);
const inviteToken = await dbClient
.collection("issuer-invite")
.findOne({ token: context.data.token });
Expand Down Expand Up @@ -130,7 +131,7 @@ async function getAuthSigningKeys(context: HookContext): Promise<SigningKey[]> {
return (await oidcClient.getSigningKeysAsync()) as SigningKey[];
}

function decodeIdToken(
function verifyIdToken(
idToken: string | undefined,
keys: SigningKey[],
context: HookContext
Expand Down

0 comments on commit cd09934

Please sign in to comment.