Skip to content
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

FI-3509: Metadata OAuth URIs #43

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/davinci_dtr_test_kit/dtr_smart_app_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DTRSmartAppSuite < Inferno::TestSuite
suite_endpoint :post, NEXT_PATH, MockPayer::NextQuestionEndpoint

# EHR
route(:get, '/fhir/metadata', MockEHR.method(:metadata))
route(:get, METADATA_PATH, MockEHR.method(:metadata))
suite_endpoint :post, QUESTIONNAIRE_RESPONSE_PATH, MockEHR::QuestionnaireResponseEndpoint
suite_endpoint :get, FHIR_RESOURCE_PATH, MockEHR::FHIRGetEndpoint
suite_endpoint :get, FHIR_SEARCH_PATH, MockEHR::FHIRGetEndpoint
Expand Down
12 changes: 10 additions & 2 deletions lib/davinci_dtr_test_kit/endpoints/mock_authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def ehr_openid_config(env)
base_url = env_base_url(env, OPENID_CONFIG_PATH)
response_body = {
issuer: base_url + FHIR_BASE_PATH,
authorization_endpoint: base_url + EHR_AUTHORIZE_PATH,
token_endpoint: base_url + EHR_TOKEN_PATH,
authorization_endpoint: authorization_endpoint(base_url),
token_endpoint: token_endpoint(base_url),
jwks_uri: base_url + JKWS_PATH,
response_types_supported: ['id_token'],
subject_types_supported: ['public'],
Expand All @@ -79,5 +79,13 @@ def env_base_url(env, endpoint_path)
path.gsub!(%r{#{endpoint_path}(/)?}, '')
"#{protocol}://#{host + path}"
end

def authorization_endpoint(base_url)
base_url + EHR_AUTHORIZE_PATH
end

def token_endpoint(base_url)
base_url + EHR_TOKEN_PATH
end
end
end
18 changes: 17 additions & 1 deletion lib/davinci_dtr_test_kit/endpoints/mock_ehr.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative '../endpoints/mock_authorization'

module DaVinciDTRTestKit
module MockEHR
RESOURCE_SERVER_BASE = ENV.fetch('FHIR_REFERENCE_SERVER')
Expand All @@ -13,9 +15,23 @@ def resource_server_client
client
end

def metadata(_env)
def metadata(env)
cs = resource_server_client.capability_statement
if cs.present?
# Overwrite the OAuth URIs returned by the reference server to point to the suite endpoints instead
oauth_uris_url = 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris'
base_url = MockAuthorization.env_base_url(env, METADATA_PATH)
sec_ext = cs.rest.first&.security&.extension&.delete_if { |e| e.url == oauth_uris_url }
sec_ext&.push(
FHIR::Extension.new(
url: oauth_uris_url,
extension: [
FHIR::Extension.new(url: 'authorize', valueUri: MockAuthorization.authorization_endpoint(base_url)),
FHIR::Extension.new(url: 'token', valueUri: MockAuthorization.token_endpoint(base_url))
]
)
)

[200, { 'Content-Type' => 'application/fhir+json', 'Access-Control-Allow-Origin' => '*' }, [cs.to_json]]
else
[500, { 'Access-Control-Allow-Origin' => '*' }, ['Unexpected error occurred while fetching metadata']]
Expand Down
1 change: 1 addition & 0 deletions lib/davinci_dtr_test_kit/urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module DaVinciDTRTestKit
FHIR_BASE_PATH = '/fhir'
METADATA_PATH = "#{FHIR_BASE_PATH}/metadata".freeze
SMART_CONFIG_PATH = "#{FHIR_BASE_PATH}/.well-known/smart-configuration".freeze
OPENID_CONFIG_PATH = "#{FHIR_BASE_PATH}/.well-known/openid-configuration".freeze
JKWS_PATH = "#{FHIR_BASE_PATH}/.well-known/jwks.json".freeze
Expand Down
Loading