Implements the SMART on FHIR authorization framework enabling third-party clinical applications to launch in context (patient, encounter) via the EHR launch sequence.
- File:
src/OAuth2/smart.controller.ts - Returns SMART on FHIR configuration document with:
authorization_endpointandtoken_endpointURLsscopes_supported: openid, fhirUser, launch/patient, patient/.read, patient/.write, patient/., user/.read, user/.write, user/., offline_accesscapabilities: launch-ehr, launch-standalone, client-public, client-confidential-symmetric, sso-openid-connect, context-passthrough-, context-ehr-patient, context-ehr-encounter, context-standalone-patient, permission-, smart-style-urlresponse_types_supported: codecode_challenge_methods_supported: S256
- File:
src/OAuth2/oauth2.controller.ts GET /oauth2/authorizeacceptslaunchparameter from the EHR- Launches the third-party app with the launch context encoded in the authorization code
- Supports
launch/patientscope for patient context resolution - Protected by
JwtAuthGuard— requires a pre-existing authenticated session
- File:
src/OAuth2/oauth2.controller.ts - Authorization code flow with PKCE (S256 code challenge method)
- Scope filtering: only SMART-relevant scopes (
patient/*,user/*,launch/patient,openid,fhirUser) are included in the access token POST /oauth2/tokenexchanges authorization code for access token with scope validationfhirUserclaim included in token whenfhirUserscope is requested
- File:
src/OAuth2/oauth2.controller.ts(lines 123-133) - When
launch/patientscope is present, the token response includes thepatientfield with the current patient ID - Patient ID is resolved from the
userIdassociated with the authorization code - Returns 401 if no patient record is linked to the user
- File:
src/OAuth2/pkce.service.ts - In-memory authorization code store with 10-minute TTL
- S256 PKCE challenge verification
- One-time use codes with client_id and redirect_uri validation
- Supports SMART launch context storage with the authorization code
- File:
test/e2e/smart-on-fhir.e2e-spec.ts - Tests
GET /.well-known/smart-configurationdiscovery endpoint - Tests full SMART EHR Launch flow:
- User registration and patient record creation
- Authorization code issuance with launch param and PKCE
- Token exchange with
launch/patientcontext resolution fhirUserscope inclusion
- Tests error cases: unsupported
response_type, invalidgrant_type
src/OAuth2/oidc.module.ts— RegisteredSmartConfigController, addedPatiententity to TypeORM importssrc/OAuth2/dto/oidc.dto.ts— Added optionallaunchparameter toOAuth2AuthorizeQueryDtosrc/OAuth2/pkce.service.ts— Addedlaunchfield toAuthCodeEntryinterface andissueCode()method
| File | Purpose |
|---|---|
src/OAuth2/smart.controller.ts |
SMART discovery endpoint |
src/OAuth2/oauth2.controller.ts |
OAuth2 authorize and token endpoints |
src/OAuth2/pkce.service.ts |
PKCE authorization code management |
src/OAuth2/oidc.module.ts |
Module wiring |
src/OAuth2/dto/oidc.dto.ts |
DTOs with SMART launch support |
test/e2e/smart-on-fhir.e2e-spec.ts |
End-to-end tests |
Closes #680