Skip to content

Commit

Permalink
Merge pull request #2131 from Infisical/daniel/azure-fix
Browse files Browse the repository at this point in the history
fix(auth): Azure audience formatting bug
  • Loading branch information
DanielHougaard authored Jul 16, 2024
2 parents de67c0a + 7ed8fee commit 9b0b14b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const validateAzureIdentity = async ({
const jwksUri = `https://login.microsoftonline.com/${tenantId}/discovery/keys`;

const decodedJwt = jwt.decode(azureJwt, { complete: true }) as TDecodedAzureAuthJwt;

const { kid } = decodedJwt.header;

const { data }: { data: TAzureJwksUriResponse } = await axios.get(jwksUri);
Expand All @@ -27,6 +28,13 @@ export const validateAzureIdentity = async ({

const publicKey = `-----BEGIN CERTIFICATE-----\n${signingKey.x5c[0]}\n-----END CERTIFICATE-----`;

// Case: This can happen when the user uses a custom resource (such as https://management.azure.com&client_id=value).
// In this case, the audience in the decoded JWT will not have a trailing slash, but the resource will.
if (!decodedJwt.payload.aud.endsWith("/") && resource.endsWith("/")) {
// eslint-disable-next-line no-param-reassign
resource = resource.slice(0, -1);
}

return jwt.verify(azureJwt, publicKey, {
audience: resource,
issuer: `https://sts.windows.net/${tenantId}/`
Expand Down

0 comments on commit 9b0b14b

Please sign in to comment.