SMART on FHIR Token Introspection Endpoint#5257
Merged
mikaelweave merged 40 commits intomainfrom Jan 12, 2026
Merged
Conversation
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api/Controllers/TokenIntrospectionController.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api/Controllers/TokenIntrospectionController.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api/Controllers/TokenIntrospectionController.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api/Controllers/TokenIntrospectionController.cs
Fixed
Show fixed
Hide fixed
mikaelweave
commented
Dec 4, 2025
src/Microsoft.Health.Fhir.Shared.Api/Controllers/TokenIntrospectionController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.Api/Features/Security/DefaultTokenIntrospectionService.cs
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.Api/Features/Security/DefaultTokenIntrospectionService.cs
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.Api/Features/Security/DefaultTokenIntrospectionService.cs
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.Api/Features/Security/DefaultTokenIntrospectionService.cs
Fixed
Show fixed
Hide fixed
…d improve logging
…ment and enhance assertions
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
Updated `DefaultTokenIntrospectionService` to use `IHttpClientFactory` for managing `HttpClient` instances and initialized a shared `ConfigurationManager` for OpenID Connect configurations. Removed inline `ConfigurationManager` instantiation in token validation logic for consistency. Enhanced `TokenIntrospectionControllerTests` by mocking `IHttpClientFactory` with `NSubstitute` to support the updated service constructor. Refactored `TokenIntrospectionTests` to improve handling of unauthenticated requests, added skipping logic for in-process test servers, and leveraged existing test infrastructure. Removed `[Consumes]` attribute from `TokenIntrospectionController` to simplify content type handling. Replaced synchronous calls with asynchronous token validation to align with best practices. Added logging and validation for `httpClientFactory` dependency. Updated namespaces across files to support new functionality.
The test `GivenContentTypeNotFormEncoded_WhenIntrospecting_ThenReturnsUnsupportedMediaType` was removed from `TokenIntrospectionTests.cs`. This test validated that the introspection endpoint returned `UnsupportedMediaType` when the content type was not `application/x-www-form-urlencoded` (per RFC 7662). Its removal suggests that this behavior is no longer relevant or required in the codebase. Other tests, such as `GivenMultipleValidTokens_WhenIntrospecting_ThenEachReturnsCorrectClaims`, remain unchanged.
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
Refactored `ValidateFormatParametersAttribute` to improve modularity by introducing `ShouldIgnoreValidation` for skipping validation on specific paths (e.g., `/CustomError`). Enhanced `Content-Type` validation for `POST`, `PUT`, and `PATCH` requests with better error handling for unsupported or missing headers.
Updated `TokenIntrospectionController` to remove the `[Authorize]` attribute, allowing unauthenticated access to `/connect/introspect`. Added `[Consumes("application/x-www-form-urlencoded")]` to specify the expected content type.
Removed a skipped test case and related code in `TokenIntrospectionTests` that validated unauthorized access to the token introspection endpoint, aligning with the updated authentication behavior.
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
…token introspection test content handling
6b7008b to
5b23a53
Compare
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…oved clarity and maintainability
…on local IDisposable Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Switch to TryGetValue for safer JSON field access in TokenIntrospectionTests, replacing ContainsKey/indexer usage. Also remove the unused _testFhirClient field for code clarity.
mikaelweave
commented
Dec 11, 2025
| /// Default implementation of token introspection for OSS (single authority/audience). | ||
| /// PaaS can extend this class and override ValidateToken() to support multiple authorities. | ||
| /// </summary> | ||
| public class DefaultTokenIntrospectionService : ITokenIntrospectionService |
Contributor
Author
There was a problem hiding this comment.
Note - this service can be overriden downstream for token validation
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
Converted all token introspection logic, endpoints, and tests to use async/await patterns. Updated ITokenIntrospectionService and DefaultTokenIntrospectionService to provide asynchronous methods. The controller endpoint now supports CancellationToken and awaits the introspection service. Replaced blocking OpenID Connect configuration retrieval with async calls. Updated all related unit tests to be asynchronous. These changes improve scalability and follow best practices for I/O-bound operations in ASP.NET Core.
Refactored TokenIntrospectionControllerTests to use a mocked ITokenIntrospectionService, removing direct JWT creation and cryptographic logic for simpler, more focused tests. Added a test to verify service invocation. Removed unused helpers and IDisposable. Updated .NET SDK version to 9.0.308. Added .runsettings and launchSettings.json files with environment variables for E2E and integration test configuration.
…ttps://github.com/microsoft/fhir-server into personal/mikaelw/smart-token-introspection-endpoint
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
… to include authorization header
- Remove keyVaultName parameter and related logic from provision-deploy.yml. - Update Azure AD authority URL to use login.microsoftonline.com. - Add logic to restore Key Vaults in removed state before provisioning. - Eliminate retry helper usage for Cosmos DB and NSP steps; use direct cmdlets. - Remove inclusion of provision-healthcheck.yml template. - Clean up comment in DevelopmentIdentityProviderRegistrationExtensions.cs.
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
src/Microsoft.Health.Fhir.Shared.Api.UnitTests/Controllers/TokenIntrospectionControllerTests.cs
Fixed
Show fixed
Hide fixed
…ttps://github.com/microsoft/fhir-server into personal/mikaelw/smart-token-introspection-endpoint
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
test/Microsoft.Health.Fhir.Shared.Tests.E2E/Rest/TokenIntrospectionTests.cs
Fixed
Show fixed
Hide fixed
…unity Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…spection tests with detailed assertions
feordin
approved these changes
Jan 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements RFC 7662 token introspection endpoint at /connect/introspect for SMART on FHIR server with swapple support for the introspection endpoint for alternate SMART configurations.
Key Features:
Related issues
Addresses AB#174822
Testing
Test Coverage:
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)