Skip to content

[HOTE-1077] feat: session token service + interfaces#353

Draft
Cormac-F-NHS wants to merge 1 commit intomainfrom
feature/hote-1077/auth-token-signing-service
Draft

[HOTE-1077] feat: session token service + interfaces#353
Cormac-F-NHS wants to merge 1 commit intomainfrom
feature/hote-1077/auth-token-signing-service

Conversation

@Cormac-F-NHS
Copy link
Copy Markdown
Contributor

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

Copilot AI review requested due to automatic review settings April 14, 2026 15:16
@github-actions
Copy link
Copy Markdown

UI Coverage Report

Lines Statements Branches Functions
Coverage: 96%
96.16% (5669/5895) 88.22% (682/773) 88.06% (214/243)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new session token signing service to the lambdas/src/lib/auth shared library along with typed JWT payload interfaces, enabling consistent generation of access/refresh session JWTs.

Changes:

  • Added SessionTokenService for signing access and refresh session tokens using jsonwebtoken (RS512).
  • Introduced typed payload interfaces for session access/refresh token claims.
  • Added unit tests covering token signing and constructor validation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
lambdas/src/lib/models/auth/session-token-payload.ts Adds interfaces describing the JWT payload shapes for session access/refresh tokens.
lambdas/src/lib/auth/session-token-service.ts Implements a token-signing service with configurable expiries and private key handling.
lambdas/src/lib/auth/session-token-service.test.ts Adds unit tests for signing behavior and private key validation.

Comment on lines +1 to +15
import { SessionTokenService } from "./session-token-service";

const mockSign = jest.fn();
const mockCleanupKey = jest.fn();

jest.mock("jsonwebtoken", () => ({
__esModule: true,
default: {
sign: mockSign,
},
}));

jest.mock("./auth-utils", () => ({
cleanupKey: mockCleanupKey,
}));
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jest mocks here are defined after the SessionTokenService import, so the module will be loaded before jsonwebtoken/auth-utils are mocked (unlike the existing auth-token tests), which is likely to call the real jwt.sign and make this test fail.
Move the import { SessionTokenService ... } to after the jest.mock(...) calls (or convert to jest.unstable_mockModule if you switch these tests to ESM mocking).

Copilot uses AI. Check for mistakes.
Comment on lines +9 to +13
export interface ISessionTokenServiceConfig {
privateKey: string;
accessTokenExpiryDurationMinutes: number;
refreshTokenExpiryDurationMinutes: number;
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISessionTokenServiceConfig introduces an I*-prefixed config interface, but the existing config type in this folder is AuthTokenVerifierConfig (no I prefix), which makes the auth module’s naming inconsistent.
Consider renaming this to SessionTokenServiceConfig (or aligning all config interfaces in src/lib/auth to the same convention).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +6
export interface IAccessTokenPayload {
sessionId: string;
sessionCreatedAt: string;
}

export interface IRefreshTokenPayload {
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payload interface names IAccessTokenPayload / IRefreshTokenPayload are very generic in a codebase that already has multiple “access tokens” (e.g. NHS Login access tokens, auth tokens), which makes imports and usage harder to understand.
Consider renaming them to be domain-specific (e.g. ISessionAccessTokenPayload / ISessionRefreshTokenPayload) and matching the file name (session-token-payload.ts).

Suggested change
export interface IAccessTokenPayload {
sessionId: string;
sessionCreatedAt: string;
}
export interface IRefreshTokenPayload {
export interface ISessionAccessTokenPayload {
sessionId: string;
sessionCreatedAt: string;
}
export interface ISessionRefreshTokenPayload {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants