@@ -252,24 +252,13 @@ function step(state::NeedRefresh)::Union{HasNewToken, NoAuthentication}
252252 refresh_token = state. token[" refresh_token" ]
253253 output = IOBuffer ()
254254 is_device = get (state. token, " client_id" , nothing ) == " device"
255- response = if is_device
256- Downloads. request (
257- joinpath (state. server, " dex/token" ),
258- method = " POST" ,
259- headers = [" Content-Type" => " application/x-www-form-urlencoded" ],
260- input = IOBuffer (" grant_type=refresh_token&client_id=device&refresh_token=$refresh_token " ),
261- output = output,
262- throw = false ,
263- )
264- else
265- Downloads. request (
266- state. token[" refresh_url" ],
267- method = " GET" ,
268- headers = [" Authorization" => " Bearer $refresh_token " ],
269- output = output,
270- throw = false ,
271- )
272- end
255+ response = Downloads. request (
256+ state. token[" refresh_url" ],
257+ method = " GET" ,
258+ headers = [" Authorization" => " Bearer $refresh_token " ],
259+ output = output,
260+ throw = false ,
261+ )
273262 # errors are recoverable by just getting a new token:
274263 if response isa Downloads. Response && response. status == 200
275264 try
@@ -281,7 +270,8 @@ function step(state::NeedRefresh)::Union{HasNewToken, NoAuthentication}
281270 end
282271 if is_device
283272 body[" client_id" ] = " device"
284- body[" expires" ] = body[" expires_in" ] + Int (floor (time ()))
273+ # refresh_url and expires/expires_at will be present in this refreshed token
274+ # so no need to manually add them here
285275 end
286276 return HasNewToken (state. server, body)
287277 catch err
@@ -410,7 +400,7 @@ function step(state::ClaimToken)::Union{ClaimToken, HasNewToken, Failure}
410400 response = Downloads. request (
411401 joinpath (state. server, " dex/token" ),
412402 method = " POST" ,
413- input = IOBuffer (reqstr ),
403+ input = IOBuffer (" client_id=device&scope=openid profile offline_access&grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code= $(state . response[ " device_code " ]) " ),
414404 output = output,
415405 throw = false ,
416406 headers = Dict (" Accept" => " application/json" , " Content-Type" => " application/x-www-form-urlencoded" ),
@@ -447,6 +437,7 @@ function step(state::ClaimToken)::Union{ClaimToken, HasNewToken, Failure}
447437 body = JSON. parse (String (take! (output)))
448438 body[" client_id" ] = " device"
449439 body[" expires" ] = body[" expires_in" ] + Int (floor (time ()))
440+ body[" refresh_url" ] = joinpath (state. server, " auth/renew/token.toml/v2/" ) # Need to be careful with auth suffix, if set
450441 return HasNewToken (state. server, body)
451442 elseif response isa Downloads. Response && response. status in [401 , 400 ] && is_device
452443 return ClaimToken (state. server, state. challenge, state. response, state. expiry, state. start_time, state. timeout, state. poll_interval, state. failures + 1 , state. max_failures)
0 commit comments