-
Notifications
You must be signed in to change notification settings - Fork 0
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-3404: Add SMART on FHIR Workflow Support to CARIN Client tests #63
Open
emichaud998
wants to merge
4
commits into
main
Choose a base branch
from
FI-3404_SMART_on_FHIR_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d4a5eb4
Add SMART authorize and token endpoints so that clients can connect v…
emichaud998 ae3fcec
Remove commented out code in token_endpoint file
emichaud998 e250aae
Update preset with client ID input and update description and README …
emichaud998 9981741
Update mock authorization to send back jwt encoded client id for toke…
emichaud998 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
32 changes: 32 additions & 0 deletions
32
lib/carin_for_blue_button_test_kit/client/v2.0.0/endpoints/authorize_endpoint.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module CarinForBlueButtonTestKit | ||
module MockAuthorization | ||
class AuthorizeEndpoint < Inferno::DSL::SuiteEndpoint | ||
def test_run_identifier | ||
request.params[:client_id] | ||
end | ||
|
||
def tags | ||
[AUTHORIZE_TAG] | ||
end | ||
|
||
def make_response | ||
if request.params[:redirect_uri].present? | ||
redirect_uri = "#{request.params[:redirect_uri]}?" \ | ||
"code=#{SecureRandom.hex}&" \ | ||
"state=#{request.params[:state]}" | ||
response.status = 302 | ||
response.headers['Location'] = redirect_uri | ||
else | ||
response.status = 400 | ||
response.format = 'application/fhir+json' | ||
response.body = FHIR::OperationOutcome.new( | ||
issue: FHIR::OperationOutcome::Issue.new(severity: 'fatal', code: 'required', | ||
details: FHIR::CodeableConcept.new( | ||
text: 'No redirect_uri provided' | ||
)) | ||
).to_json | ||
end | ||
end | ||
end | ||
end | ||
end |
4 changes: 3 additions & 1 deletion
4
lib/carin_for_blue_button_test_kit/client/v2.0.0/endpoints/next_page_endpoint.rb
This file contains 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
4 changes: 3 additions & 1 deletion
4
lib/carin_for_blue_button_test_kit/client/v2.0.0/endpoints/resource_api_endpoint.rb
This file contains 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
4 changes: 3 additions & 1 deletion
4
lib/carin_for_blue_button_test_kit/client/v2.0.0/endpoints/resource_id_endpoint.rb
This file contains 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
104 changes: 91 additions & 13 deletions
104
lib/carin_for_blue_button_test_kit/client/v2.0.0/endpoints/token_endpoint.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,102 @@ | ||
require_relative '../tags' | ||
require_relative '../urls' | ||
require_relative '../mock_server' | ||
require_relative '../mock_authorization' | ||
|
||
module CarinForBlueButtonTestKit | ||
class TokenEndpoint < Inferno::DSL::SuiteEndpoint | ||
include CarinForBlueButtonTestKit::MockServer | ||
module MockAuthorization | ||
AUTHORIZED_PRACTITIONER_ID = 'c4bb-Practitioner'.freeze # Must exist on the FHIR_REFERENCE_SERVER (env var) | ||
CARIN_PATIENT_ID = '888'.freeze # Must exist on the FHIR_REFERENCE_SERVER (env var) | ||
|
||
def test_run_identifier | ||
extract_client_id(request) | ||
end | ||
class TokenEndpoint < Inferno::DSL::SuiteEndpoint | ||
include CarinForBlueButtonTestKit::MockServer | ||
|
||
def make_response | ||
token_response(request) | ||
end | ||
def test_run_identifier | ||
extract_client_id | ||
end | ||
|
||
def tags | ||
[AUTH_TAG] | ||
end | ||
def tags | ||
[TOKEN_TAG] | ||
end | ||
|
||
def make_response | ||
client_id = extract_client_id | ||
access_token = JWT.encode({ inferno_client_id: client_id }, nil, 'none') | ||
granted_scopes = SUPPORTED_SCOPES & requested_scopes | ||
|
||
response_hash = { access_token:, scope: granted_scopes.join(' '), token_type: 'bearer', | ||
expires_in: 3600 } | ||
|
||
if granted_scopes.include?('openid') | ||
response_hash.merge!(id_token: create_id_token(client_id, | ||
fhir_user: granted_scopes.include?('fhirUser'))) | ||
end | ||
|
||
response_hash.merge!(patient: CARIN_PATIENT_ID) | ||
|
||
response.body = response_hash.to_json | ||
response.headers['Cache-Control'] = 'no-store' | ||
response.headers['Pragma'] = 'no-cache' | ||
response.headers['Access-Control-Allow-Origin'] = '*' | ||
response.status = 200 | ||
end | ||
|
||
private | ||
|
||
def extract_client_id | ||
# Public client || confidential client asymmetric || confidential client symmetric | ||
request.params[:client_id] || extract_client_id_from_client_assertion || extract_client_id_from_basic_auth | ||
end | ||
|
||
def extract_client_id_from_client_assertion | ||
encoded_jwt = request.params[:client_assertion] | ||
return unless encoded_jwt.present? | ||
|
||
jwt_payload = | ||
begin | ||
JWT.decode(encoded_jwt, nil, false)&.first # skip signature verification | ||
rescue StandardError | ||
nil | ||
end | ||
|
||
jwt_payload['iss'] || jwt_payload['sub'] if jwt_payload.present? | ||
end | ||
|
||
def extract_client_id_from_basic_auth | ||
encoded_credentials = request.headers['authorization']&.delete_prefix('Basic ') | ||
return unless encoded_credentials.present? | ||
|
||
decoded_credentials = Base64.decode64(encoded_credentials) | ||
decoded_credentials&.split(':')&.first | ||
end | ||
|
||
def requested_scopes | ||
auth_request = requests_repo.tagged_requests(result.test_session_id, [AUTHORIZE_TAG]).last | ||
return [] unless auth_request | ||
|
||
auth_params = if auth_request.verb.downcase == 'get' | ||
auth_request.query_parameters | ||
else | ||
URI.decode_www_form(auth_request.request_body)&.to_h | ||
end | ||
scope_str = auth_params&.dig('scope') | ||
scope_str ? URI.decode_www_form_component(scope_str).split : [] | ||
end | ||
|
||
def create_id_token(client_id, fhir_user: false) | ||
# No point in mocking an identity provider, just always use known Practitioner as the authorized user | ||
suite_fhir_base_url = request.url.split(TOKEN_PATH).first + BASE_FHIR_PATH | ||
id_token_hash = { | ||
iss: suite_fhir_base_url, | ||
sub: AUTHORIZED_PRACTITIONER_ID, | ||
aud: client_id, | ||
exp: Time.now.to_i + (24 * 60 * 60), # 24 hrs | ||
iat: Time.now.to_i | ||
} | ||
id_token_hash.merge!(fhirUser: "#{suite_fhir_base_url}/Practitioner/#{AUTHORIZED_PRACTITIONER_ID}") if fhir_user | ||
|
||
def update_result | ||
results_repo.update(result.id, result: 'pass') unless test.config.options[:accepts_multiple_requests] | ||
JWT.encode(id_token_hash, RSA_PRIVATE_KEY, 'RS256') | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
If you're serving a signed ID token, I think you need to also expose the public key in a JWKS, e.g. https://github.com/inferno-framework/davinci-dtr-test-kit/blob/main/lib/davinci_dtr_test_kit/endpoints/mock_authorization.rb#L20