-
Notifications
You must be signed in to change notification settings - Fork 574
SMART on FHIR Token Introspection Endpoint #5257
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
base: main
Are you sure you want to change the base?
SMART on FHIR Token Introspection Endpoint #5257
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
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
|
/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.
| 'app_globalReaderUserApp_secret': $(app_globalReaderUserApp_secret) | ||
| 'app_globalWriterUserApp_id': $(app_globalWriterUserApp_id) | ||
| 'app_globalWriterUserApp_secret': $(app_globalWriterUserApp_secret) | ||
| 'app_smartUserClient_id': $(app_smartUserClient_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed for E2E tests that use SMART client
| serviceName = $webAppName | ||
| keyVaultName = "${{ parameters.keyVaultName }}".ToLower() | ||
| securityAuthenticationAuthority = "https://login.microsoftonline.com/$(tenant-id)" | ||
| securityAuthenticationAuthority = "https://sts.windows.net/$(tenant-id-guid)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our test env has been using an invalid authority for ... not sure how long. I reuse the authority in the OSS service to check the token so I had to fix the authority.
src/Microsoft.Health.Fhir.Api/Features/Filters/ValidateFormatParametersAttribute.cs
Outdated
Show resolved
Hide resolved
| /// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
/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
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)