@@ -175,10 +175,18 @@ struct NoAuthentication <: State
175175end
176176Base. show (io:: IO , s:: NoAuthentication ) = print (io, " NoAuthentication($(s. server) , $(s. auth_suffix) )" )
177177
178+ function get_device_auth_client_id ()
179+ return get (ENV , " JULIA_PKG_AUTHENTICATION_DEVICE_CLIENT_ID" , " " )
180+ end
181+
182+ function should_use_device_auth ()
183+ return ! isempty (get_device_auth_client_id ())
184+ end
185+
178186function get_openid_configuration (state:: NoAuthentication )
179187 output = IOBuffer ()
180188 response = Downloads. request (
181- joinpath (state. server, " dex/ .well-known/openid-configuration" ),
189+ joinpath (state. server, " .well-known/openid-configuration" ),
182190 method = " GET" ,
183191 output = output,
184192 throw = false ,
@@ -195,15 +203,22 @@ function get_openid_configuration(state::NoAuthentication)
195203 return false , " " , " "
196204 end
197205
198- return body != = nothing && haskey (body, " device_authorization_endpoint" ) && haskey (body, " grant_types_supported" ) && " urn:ietf:params:oauth:grant-type:device_code" in body[" grant_types_supported" ], body[" device_authorization_endpoint" ], body[" token_endpoint" ]
206+ if body != = nothing
207+ return true , body[" device_authorization_endpoint" ], body[" token_endpoint" ]
208+ end
199209 end
200210
201211 return false , " " , " "
202212end
203213
204214function step (state:: NoAuthentication ):: Union{RequestLogin, Failure}
205- device_tokens_supported, device_endpoint, token_endpoint = get_openid_configuration (state)
206- success, challenge, body_or_response = if device_tokens_supported
215+ token_endpoint = " "
216+ device_endpoint = " "
217+ if should_use_device_auth ()
218+ s, device_endpoint, token_endpoint = get_openid_configuration (state)
219+ s || GenericError (" Unable to get device and token endpoints" )
220+ end
221+ success, challenge, body_or_response = if should_use_device_auth ()
207222 fetch_device_code (state, device_endpoint)
208223 else
209224 initiate_browser_challenge (state)
0 commit comments