Skip to content

Commit

Permalink
fix: audience is now a required JWT claim for idToken (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Jun 24, 2024
1 parent a94b270 commit c1730e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/auth-provider/src/common/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ export const serviceCall = async ({ params = {} }: ServiceCallProps) => {
}
};

export const verifyAndExtractToken = async (token: string) => {
export const verifyAndExtractToken = async (
token: string,
audience: string,
) => {
try {
const alg = JWT.ALG;
const spki = JWT_PUBLIC_KEY;
const publicKey = await jose.importSPKI(spki, alg);
return await jose.jwtVerify(token, publicKey, {
issuer: JWT.ISSUER,
audience,
});
} catch (_error) {
return undefined;
Expand Down Expand Up @@ -79,7 +83,7 @@ export const authenticateUser = async ({
clientId,
},
});
const jwt = await verifyAndExtractToken(response.data.idToken);
const jwt = await verifyAndExtractToken(response.data.idToken, clientId);
if (jwt && jwt.payload[JWT.USER_ID_KEY] !== "") {
return {
idToken: response.data.idToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const AuthProvider = ({
if (previousIdToken !== idToken && idToken !== null) {
(async () => {
try {
const jwt = await verifyAndExtractToken(idToken);
const jwt = await verifyAndExtractToken(idToken, clientId);
if (jwt && jwt.payload[JWT.USER_ID_KEY] !== "") {
setAuthState({
isAuthenticated: true,
Expand All @@ -58,7 +58,7 @@ export const AuthProvider = ({
}
})();
}
}, [idToken, previousIdToken]);
}, [idToken, previousIdToken, clientId]);

const login = async (
username: string,
Expand Down

0 comments on commit c1730e7

Please sign in to comment.