From b504fb7bd2f3e92e5a193e4363af6ff5b02c13cf Mon Sep 17 00:00:00 2001 From: Oskar Stangenberg Date: Fri, 14 Feb 2025 14:13:03 +0100 Subject: [PATCH] Added the tenant and product as prefix to the OIDC subject. --- npm/src/controller/oauth.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/npm/src/controller/oauth.ts b/npm/src/controller/oauth.ts index 9372d6e14..c33f8311a 100644 --- a/npm/src/controller/oauth.ts +++ b/npm/src/controller/oauth.ts @@ -1330,16 +1330,24 @@ export class OAuthController implements IOAuthController { }; const signingKey = await loadJWSPrivateKey(jwtSigningKeys.private, jwsAlg!); const kid = await computeKid(jwtSigningKeys.public, jwsAlg!); + let subjectPrefix = "" + if(codeVal.requested?.tenant) { + subjectPrefix += `${codeVal.requested.tenant}|`; + } + if(codeVal.requested?.product) { + subjectPrefix += `${codeVal.requested.product}|`; + } + const subject_id = subjectPrefix + codeVal.profile.claims.id; const id_token = await new jose.SignJWT(claims) .setProtectedHeader({ alg: jwsAlg!, kid }) .setIssuedAt() .setIssuer(this.opts.externalUrl) - .setSubject(codeVal.profile.claims.id) + .setSubject(subject_id) .setAudience(tokenVal.requested.client_id) .setExpirationTime(`${this.opts.db.ttl}s`) // identity token only really needs to be valid long enough for it to be verified by the client application. .sign(signingKey); tokenVal.id_token = id_token; - tokenVal.claims.sub = codeVal.profile.claims.id; + tokenVal.claims.sub = subject_id; } const { hexKey, encVal } = encrypt(tokenVal);