Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ATO-1302: Add auth_time to id token #236

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/token/helper/create-id-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const createIdTokenClaimSet = (
? randomBytes(32).toString()
: authRequestParams.nonce,
vtm: config.getTrustmarkUrl(),
auth_time: timeNow,
};
};

Expand Down
2 changes: 2 additions & 0 deletions src/components/token/tests/helper/create-id-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("createIdToken tests", () => {
vtm: "http://localhost:3000/trustmark",
vot: "Cl.Cm",
nonce: mockAuthRequestParams.nonce,
auth_time: Math.floor(testTimestampMs / 1000),
});
expect(typeof tokenParts[2]).toBe("string");
});
Expand Down Expand Up @@ -108,6 +109,7 @@ describe("createIdToken tests", () => {
vtm: "http://localhost:3000/trustmark",
vot: mockAuthRequestParams.vtr.credentialTrust,
nonce: mockAuthRequestParams.nonce,
auth_time: Math.floor(testTimestampMs / 1000),
});
expect(typeof tokenParts[2]).toBe("string");
});
Expand Down
1 change: 1 addition & 0 deletions src/types/id-token-claims.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type IdTokenClaims = {
nonce: string;
vtm: string;
sid: string;
auth_time: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ import {
SESSION_ID,
VALID_CLAIMS,
RSA_PRIVATE_TOKEN_SIGNING_KEY,
ID_TOKEN_EXPIRY,
} from "../../src/constants";
import { decodeJwtNoVerify } from "./helper/decode-jwt-no-verify";

const TOKEN_ENDPOINT = "/token";

const TIME_NOW = 1736789549;
jest.useFakeTimers().setSystemTime(TIME_NOW);
cearl1 marked this conversation as resolved.
Show resolved Hide resolved

const rsaKeyPair = generateKeyPairSync("rsa", {
modulusLength: 2048,
});
Expand Down Expand Up @@ -72,7 +76,7 @@ const createClientAssertionPayload = (
isExpired = false
) =>
new UnsecuredJWT(payload)
.setIssuedAt(Math.floor(Date.now() / 1000))
.setIssuedAt(Math.floor(TIME_NOW / 1000))
.setExpirationTime(isExpired ? "-1h" : "1h")
.setJti(randomUUID())
.setAudience(audience)
Expand Down Expand Up @@ -438,8 +442,8 @@ describe("/token endpoint tests, invalid client assertion", () => {
sub: knownClientId,
aud: "https://identity-provider.example.com/token",
jti: randomUUID(),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(TIME_NOW / 1000),
exp: Math.floor(TIME_NOW / 1000) + 3600,
}) +
"." +
fakeSignature();
Expand Down Expand Up @@ -477,8 +481,8 @@ describe("/token endpoint, configured error responses", () => {
sub: knownClientId,
aud: audience,
jti: randomUUID(),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(TIME_NOW / 1000),
exp: Math.floor(TIME_NOW / 1000) + 3600,
}),
};
});
Expand Down Expand Up @@ -538,7 +542,7 @@ describe("/token endpoint, configured error responses", () => {
const response = await request(app).post(TOKEN_ENDPOINT).send(validRequest);
const { id_token } = response.body;
const { payload } = decodeJwtNoVerify(id_token);
expect(payload.iat).toBeGreaterThan(Date.now() / 1000);
expect(payload.iat).toBe(Math.floor(TIME_NOW / 1000) + 86400);
});

it("returns an expired token if the client config has enabled TOKEN_EXPIRED", async () => {
Expand All @@ -551,7 +555,7 @@ describe("/token endpoint, configured error responses", () => {
const response = await request(app).post(TOKEN_ENDPOINT).send(validRequest);
const { id_token } = response.body;
const { payload } = decodeJwtNoVerify(id_token);
expect(payload.iat).toBeLessThan(Date.now() / 1000);
expect(payload.iat).toBe(Math.floor(TIME_NOW / 1000));
});

it("returns an invalid aud if the client config has enabled INVALID_AUD", async () => {
Expand Down Expand Up @@ -612,8 +616,8 @@ describe("/token endpoint valid client_assertion", () => {
sub: knownClientId,
aud: audience,
jti: randomUUID(),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(TIME_NOW / 1000),
exp: Math.floor(TIME_NOW / 1000) + 3600,
});

const app = createApp();
Expand Down Expand Up @@ -643,8 +647,8 @@ describe("/token endpoint valid client_assertion", () => {
sub: knownClientId,
aud: audience,
jti: randomUUID(),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(TIME_NOW / 1000),
exp: Math.floor(TIME_NOW / 1000) + 3600,
});

const app = createApp();
Expand Down Expand Up @@ -674,8 +678,8 @@ describe("/token endpoint valid client_assertion", () => {
sub: knownClientId,
aud: audience,
jti: randomUUID(),
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 3600,
iat: Math.floor(TIME_NOW / 1000),
exp: Math.floor(TIME_NOW / 1000) + 3600,
});

const app = createApp();
Expand Down Expand Up @@ -722,5 +726,10 @@ describe("/token endpoint valid client_assertion", () => {
expect(decodedIdToken.payload.vot).toBe(
validAuthRequestParams.vtr.credentialTrust
);
expect(decodedIdToken.payload.iat).toBe(Math.floor(TIME_NOW / 1000));
expect(decodedIdToken.payload.exp).toBe(
Math.floor(TIME_NOW / 1000) + ID_TOKEN_EXPIRY
);
expect(decodedIdToken.payload.auth_time).toBe(Math.floor(TIME_NOW / 1000));
});
});
Loading