UNPKG

fhir-kit-client

Version:
52 lines 1.95 kB
import { logError } from './logging.js'; const smartOauthUrl = 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris'; /** * Extract SMART OAuth URLs from a FHIR CapabilityStatement. */ export function authFromCapability(capabilityStatement) { const authMetadata = {}; try { const restItems = capabilityStatement.rest; if (!restItems) return authMetadata; for (const restItem of restItems) { const uris = restItem.security?.extension?.find((x) => x.url === smartOauthUrl); if (!uris?.extension) continue; for (const ext of uris.extension) { if (!ext.valueUri) continue; switch (ext.url) { case 'authorize': authMetadata.authorizeUrl = new URL(ext.valueUri); break; case 'token': authMetadata.tokenUrl = new URL(ext.valueUri); break; case 'register': authMetadata.registerUrl = new URL(ext.valueUri); break; case 'manage': authMetadata.manageUrl = new URL(ext.valueUri); break; } } } } catch (error) { logError(error); } return authMetadata; } /** * Extract SMART OAuth URLs from a .well-known configuration document. */ export function authFromWellKnown(wellKnown) { const config = wellKnown; return { authorizeUrl: config.authorization_endpoint ? new URL(config.authorization_endpoint) : undefined, tokenUrl: config.token_endpoint ? new URL(config.token_endpoint) : undefined, registerUrl: config.registration_endpoint ? new URL(config.registration_endpoint) : undefined, }; } //# sourceMappingURL=smart.js.map