misc: addressed review comments

This commit is contained in:
Sheen Capadngan
2024-12-13 13:39:23 +08:00
parent a7b25f3bd8
commit c35657ed49
10 changed files with 48 additions and 18 deletions

View File

@@ -99,6 +99,7 @@ import {
TIdentityGcpAuthsInsert,
TIdentityGcpAuthsUpdate,
TIdentityJwtAuths,
TIdentityJwtAuthsInsert,
TIdentityJwtAuthsUpdate,
TIdentityKubernetesAuths,
TIdentityKubernetesAuthsInsert,

View File

@@ -94,17 +94,17 @@ const UpdateBaseSchema = z
.partial();
const JwksConfigurationSchema = z.object({
configurationType: z.literal(JwtConfigurationType.JWKS),
jwksUrl: z.string().trim().url(),
jwksCaCert: z.string().trim().default(""),
publicKeys: z.string().array().optional().default([])
configurationType: z.literal(JwtConfigurationType.JWKS).describe(JWT_AUTH.ATTACH.configurationType),
jwksUrl: z.string().trim().url().describe(JWT_AUTH.ATTACH.jwksUrl),
jwksCaCert: z.string().trim().default("").describe(JWT_AUTH.ATTACH.jwksCaCert),
publicKeys: z.string().array().optional().default([]).describe(JWT_AUTH.ATTACH.publicKeys)
});
const StaticConfigurationSchema = z.object({
configurationType: z.literal(JwtConfigurationType.STATIC),
jwksUrl: z.string().trim().optional().default(""),
jwksCaCert: z.string().trim().optional().default(""),
publicKeys: z.string().min(1).array().min(1)
configurationType: z.literal(JwtConfigurationType.STATIC).describe(JWT_AUTH.ATTACH.configurationType),
jwksUrl: z.string().trim().optional().default("").describe(JWT_AUTH.ATTACH.jwksUrl),
jwksCaCert: z.string().trim().optional().default("").describe(JWT_AUTH.ATTACH.jwksCaCert),
publicKeys: z.string().min(1).array().min(1).describe(JWT_AUTH.ATTACH.publicKeys)
});
export const registerIdentityJwtAuthRouter = async (server: FastifyZodProvider) => {

View File

@@ -1,4 +1,9 @@
import picomatch from "picomatch";
export const doesFieldValueMatchJwtPolicy = (fieldValue: string, policyValue: string) =>
policyValue === fieldValue || picomatch.isMatch(fieldValue, policyValue);
export const doesFieldValueMatchJwtPolicy = (fieldValue: string | boolean, policyValue: string) => {
if (typeof fieldValue === "boolean") {
return fieldValue === (policyValue === "true");
}
return policyValue === fieldValue || picomatch.isMatch(fieldValue, policyValue);
};

View File

@@ -75,7 +75,7 @@ export const identityJwtAuthServiceFactory = ({
});
}
let tokenData: Record<string, string> = {};
let tokenData: Record<string, string | boolean> = {};
if (identityJwtAuth.configurationType === JwtConfigurationType.JWKS) {
const decryptedJwksCaCert = orgDataKeyDecryptor({
@@ -127,13 +127,7 @@ export const identityJwtAuthServiceFactory = ({
}
if (identityJwtAuth.boundIssuer) {
if (!tokenData.iss) {
throw new UnauthorizedError({
message: "Access denied: token has no issuer field"
});
}
if (!doesFieldValueMatchJwtPolicy(tokenData.iss, identityJwtAuth.boundIssuer)) {
if (tokenData.iss !== identityJwtAuth.boundIssuer) {
throw new ForbiddenRequestError({
message: "Access denied: issuer mismatch"
});

View File

@@ -0,0 +1,4 @@
---
title: "Attach"
openapi: "POST /api/v1/auth/jwt-auth/identities/{identityId}"
---

View File

@@ -0,0 +1,4 @@
---
title: "Login"
openapi: "POST /api/v1/auth/jwt-auth/login"
---

View File

@@ -0,0 +1,4 @@
---
title: "Retrieve"
openapi: "GET /api/v1/auth/jwt-auth/identities/{identityId}"
---

View File

@@ -0,0 +1,4 @@
---
title: "Revoke"
openapi: "DELETE /api/v1/auth/jwt-auth/identities/{identityId}"
---

View File

@@ -0,0 +1,4 @@
---
title: "Update"
openapi: "PATCH /api/v1/auth/jwt-auth/identities/{identityId}"
---

View File

@@ -583,6 +583,16 @@
"api-reference/endpoints/oidc-auth/revoke"
]
},
{
"group": "JWT Auth",
"pages": [
"api-reference/endpoints/jwt-auth/login",
"api-reference/endpoints/jwt-auth/attach",
"api-reference/endpoints/jwt-auth/retrieve",
"api-reference/endpoints/jwt-auth/update",
"api-reference/endpoints/jwt-auth/revoke"
]
},
{
"group": "Groups",
"pages": [