Skip to content

Decode managed identity token for dicom API routes#1355

Merged
steventux merged 8 commits intomainfrom
feat/validate-managed-identity-token-for-dicom-api
Apr 29, 2026
Merged

Decode managed identity token for dicom API routes#1355
steventux merged 8 commits intomainfrom
feat/validate-managed-identity-token-for-dicom-api

Conversation

@steventux
Copy link
Copy Markdown
Contributor

@steventux steventux commented Apr 20, 2026

Description

We will authenticate dicom API requests using a token generated by a system assigned managed identity.
See NHSDigital/manage-breast-screening-gateway#96 for how we will do this.
This PR adds AD based token authentication for all dicom routes.

Jira link

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-12807

and part of

https://nhsd-jira.digital.nhs.uk/browse/DTOSS-12648

Review notes

Not covered in this PR: How we authorise the incoming request (spoilers: using the oid auth claim)

Review checklist

  • Check database queries are correctly scoped to current_provider
  • If this changes the gateway API (/api/v1/), confirm whether it is a breaking change — if so, a new major version (/api/v2/) is required (see ADR-006)

Comment thread manage_breast_screening/dicom/token_validator.py Outdated
Comment thread manage_breast_screening/dicom/token_validator.py Outdated
Comment thread manage_breast_screening/dicom/token_validator.py Outdated
@steventux steventux changed the title Feat/validate managed identity token for dicom api Validate managed identity token for dicom API routes Apr 21, 2026
@steventux steventux force-pushed the feat/validate-managed-identity-token-for-dicom-api branch from 5475223 to 7c46fbb Compare April 27, 2026 14:26
@steventux steventux changed the title Validate managed identity token for dicom API routes Decode managed identity token for dicom API routes Apr 27, 2026
@steventux steventux marked this pull request as ready for review April 27, 2026 14:32
Comment thread manage_breast_screening/dicom/authentication.py
"""
The expected issuer claim(s) in the JWT token. This should match the tenant ID and the Azure AD endpoints.
"""
return [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe worth constantising these?

AZURE_AD_V1_ISSUER_TEMPLATE = "https://sts.windows.net/{tenant_id}/"
AZURE_AD_V2_ISSUER_TEMPLATE = "https://login.microsoftonline.com/{tenant_id}/v2.0/"

or some such

Copy link
Copy Markdown
Contributor Author

@steventux steventux Apr 28, 2026

Choose a reason for hiding this comment

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

This didn't work without converting tenant id to a constant too. something to do with the templating.
I've cached the string/array properties which use tenant id to prevent unnecessary interpolation, this has the benefit of docstrings in the body of the property definition.

@steventux steventux force-pushed the feat/validate-managed-identity-token-for-dicom-api branch from a682f89 to a2c81a5 Compare April 28, 2026 15:52
The JWKSClient caches the keys from the given discovery keys endpoint, so this property should also be cached on the Authentication instance.
Cache a couple of other properties we only need to create once per instance.
@steventux steventux force-pushed the feat/validate-managed-identity-token-for-dicom-api branch from a2c81a5 to 5c12134 Compare April 28, 2026 15:57
@sonarqubecloud
Copy link
Copy Markdown

@steventux steventux merged commit 5cfcf51 into main Apr 29, 2026
12 checks passed
@steventux steventux deleted the feat/validate-managed-identity-token-for-dicom-api branch April 29, 2026 13:45
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.

3 participants