@@ -122,6 +122,7 @@ function authenticate(;
122122 state = initial (server)
123123 try
124124 while ! (isa (state, Success) || isa (state, Failure))
125+ @debug " Calling step(::$(typeof (state)) )"
125126 state = step (state)
126127 end
127128 catch err
@@ -227,20 +228,33 @@ function step(state::NeedRefresh)::Union{HasNewToken, NoAuthentication}
227228 # errors are recoverable by just getting a new token:
228229 if response isa Downloads. Response && response. status == 200
229230 try
230- body = JSON. parse (String (take! (output)))
231- if haskey (body, " token" )
232- return HasNewToken (state. server, body[" token" ])
231+ body = TOML. parse (String (take! (output)))
232+ let msg = " token refresh response"
233+ assert_dict_keys (body, " access_token" , " id_token" ; msg= msg)
234+ assert_dict_keys (body, " expires_in" ; msg= msg)
235+ assert_dict_keys (body, " expires" , " expires_at" ; msg= msg)
233236 end
237+ return HasNewToken (state. server, body)
234238 catch err
235239 @debug " invalid body received while refreshing token" exception= (err, catch_backtrace ())
236240 end
237241 return NoAuthentication (state. server)
238242 else
239- @debug " request for refreshing token failed" exception = (err, catch_backtrace ())
243+ @debug " request for refreshing token failed" response
240244 return NoAuthentication (state. server)
241245 end
242246end
243247
248+ function assert_dict_keys (dict:: Dict , keys... ; msg:: AbstractString )
249+ any (haskey (dict, key) for key in keys) && return nothing
250+ if length (keys) == 1
251+ error (" Key '$(first (keys)) ' not present in $msg " )
252+ else
253+ keys = join (string .(" '" , keys, " '" ), " , " )
254+ error (" None of $keys present in $msg " )
255+ end
256+ end
257+
244258"""
245259Takes the token from the previous step and writes it to the auth.toml file. In order
246260to handle potential race conditions with other writes, it will check that the write
0 commit comments