Skip to content

Commit

Permalink
Add option to pass own downloader to refresh (#29)
Browse files Browse the repository at this point in the history
* Add option to pass own downloader to refresh

* Add downloader option to other refresh methods
  • Loading branch information
quinnj authored Jun 14, 2024
1 parent 8eeb318 commit c05abb3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/JWTs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,26 +251,26 @@ If the keyseturl is not specified, the keyset is refreshed with the keys from th
The default algorithm values are referred to only if the keyset does not specify the exact algorithm type.
E.g. if only "RSA" is specified as the algorithm, "RS256" will be assumed.
"""
function refresh!(keyset::JWKSet, keyseturl::String; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"))
function refresh!(keyset::JWKSet, keyseturl::String; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"), downloader=nothing)
keyset.url = keyseturl
refresh!(keyset; default_algs=default_algs)
refresh!(keyset; default_algs=default_algs, downloader=downloader)
end

function refresh!(keyset::JWKSet; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"))
function refresh!(keyset::JWKSet; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"), downloader=nothing)
if !isempty(keyset.url)
keys = Dict{String,JWK}()
refresh!(keyset.url, keys; default_algs=default_algs)
refresh!(keyset.url, keys; default_algs=default_algs, downloader=downloader)
keyset.keys = keys
end
nothing
end

function refresh!(keyseturl::String, keysetdict::Dict{String,JWK}; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"))
function refresh!(keyseturl::String, keysetdict::Dict{String,JWK}; default_algs = Dict("RSA" => "RS256", "oct" => "HS256"), downloader=nothing)
if startswith(keyseturl, "file://")
jstr = readchomp(keyseturl[8:end])
else
output = PipeBuffer()
Downloads.request(keyseturl; method="GET", output=output)
Downloads.request(keyseturl; method="GET", output=output, downloader=downloader)
jstr = String(take!(output))
end
keys = JSON.parse(jstr)["keys"]
Expand Down

0 comments on commit c05abb3

Please sign in to comment.