Skip to content

Commit

Permalink
Split grant_type and scope into two separate fields (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge authored Feb 21, 2022
1 parent afe006c commit ba6c4ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EHRAuthentication"
uuid = "45047142-e73a-4b31-ae20-3729a1bbef33"
authors = ["Dilum Aluthge", "Pumas-AI, Inc.", "contributors"]
version = "1.0.0"
version = "2.0.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
10 changes: 8 additions & 2 deletions src/Cerner/system_accounts.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Base.@kwdef struct CernerConfig
base_url::String
grant_type::String = "client_credentials"
headers::Dict{String, String} = Dict{String, String}()
scope::String = "grant_type=client_credentials&scope=system%2FObservation.read%20system%2FPatient.read"
scope::String # Example: scope = "system/Patient.read system/Observation.read"
system_account_client_id::String
system_account_client_secret::String
end
Expand All @@ -14,6 +15,7 @@ end

function authenticate_fhir_cerner(config::CernerConfig)
base_url = config.base_url
grant_type = config.grant_type
headers = config.headers
scope = config.scope
system_account_client_id = config.system_account_client_id
Expand Down Expand Up @@ -54,10 +56,14 @@ function authenticate_fhir_cerner(config::CernerConfig)
for (k, v) in headers
current_headers[k] = v
end
body = string(
"grant_type=$(HTTP.escapeuri(grant_type))&",
"scope=$(HTTP.escapeuri(scope))&",
)
token_response = HTTP.request("POST",
endpoints["token"],
current_headers,
scope,
body,
)
token_response_body = JSON3.read(String(token_response.body))
token_dict = copy(token_response_body)
Expand Down

0 comments on commit ba6c4ea

Please sign in to comment.