Skip to content

Commit

Permalink
Try Base64-decoding state with each of the three possible amounts o…
Browse files Browse the repository at this point in the history
…f padding (#48)

* Try Base64-decoding `state` with each of the three possible amounts of padding

* Bump the version number from "2.0.0" to "2.0.1"
  • Loading branch information
DilumAluthge authored May 17, 2022
1 parent b5b2cfb commit cf192e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SMARTAppLaunch"
uuid = "d2818e16-7729-416e-a683-becc19f3d01b"
authors = ["Dilum Aluthge", "contributors"]
version = "2.0.0"
version = "2.0.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
27 changes: 19 additions & 8 deletions src/provider/ehr_launch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,24 @@ function provider_ehr_launch_part_two(
return location_queryparams
end

@static if Base.VERSION >= v"1.9-"
const my_base64decode = Base64.base64decode
else
# padding is needed for `base64decode` to work on older versions of Julia
# https://github.com/JuliaLang/julia/pull/44503
function my_base64decode(str::AbstractString)
try
Base64.base64decode(str)
catch
try
Base64.base64decode(str * "=")
catch
Base64.base64decode(str * "==")
end
end
end
end

"""
provider_ehr_launch_part_three(
config::ProviderEHRLaunchConfig,
Expand All @@ -210,14 +228,7 @@ function provider_ehr_launch_part_three(
end
authorization_code = location_queryparams["code"]::String
state = location_queryparams["state"]::String
@static if Base.VERSION < v"1.9-"
# padding is needed for `base64decode` to work on older versions of Julia
# https://github.com/JuliaLang/julia/pull/44503
if !endswith(state, "==")
state = state * "=="
end
end
state_json = Base64.base64decode(state)
state_json = my_base64decode(state)
state_dict = JSON3.read(state_json)
token_endpoint_original = state_dict[:token_endpoint]::String
token_endpoint_stripped = strip(token_endpoint_original)
Expand Down

2 comments on commit cf192e1

@Vaibhavdixit02
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60390

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.0.1 -m "<description of version>" cf192e1b105e2fbddeba4111200f50f827531bb8
git push origin v2.0.1

Please sign in to comment.