@@ -50,7 +50,7 @@ mutable struct Authentication
5050 tokenpath:: Union{AbstractString, Nothing} = nothing ,
5151 email:: Union{AbstractString, Nothing} = nothing ,
5252 expires:: Union{Integer, Nothing} = nothing ,
53- project_uuid :: Union{UUIDs.UUID, Nothing} = nothing ,
53+ project_id :: Union{UUIDs.UUID, Nothing} = nothing ,
5454 )
5555 # The authentication() function should take care of sanitizing the inputs here,
5656 # so it is fine to just error() here.
@@ -61,7 +61,7 @@ mutable struct Authentication
6161 @warn " Invalid auth.toml token path passed to Authentication, ignoring." tokenpath
6262 tokenpath = nothing
6363 end
64- new (server, username, token, project_uuid , api_version, tokenpath, email, expires)
64+ new (server, username, token, project_id , api_version, tokenpath, email, expires)
6565 end
6666end
6767
@@ -232,10 +232,14 @@ This can be set by passing the optional `project` argument, which works as follo
232232"""
233233function authenticate end
234234
235- function authenticate (server:: AbstractString , token:: Union{AbstractString, Secret} )
235+ function authenticate (
236+ server:: AbstractString , token:: Union{AbstractString, Secret} ;
237+ project:: Union{AbstractString, UUIDs.UUID, Nothing, Missing} = missing ,
238+ )
236239 auth = _authentication (
237240 _juliahub_uri (server);
238241 token= isa (token, Secret) ? token : Secret (token),
242+ project_id= _juliahub_project (project),
239243 )
240244 global __AUTH__[] = auth
241245 return auth
@@ -256,9 +260,9 @@ function authenticate(
256260 ),
257261 )
258262 end
259- project_uuid = _normalize_project (project)
263+ project_id = _juliahub_project (project)
260264 server_uri = _juliahub_uri (server)
261- auth = Mocking. @mock _authenticate (server_uri; force, maxcount, hook, project_uuid )
265+ auth = Mocking. @mock _authenticate (server_uri; force, maxcount, hook, project_id )
262266 global __AUTH__[] = auth
263267 return auth
264268end
@@ -291,14 +295,14 @@ end
291295function _authenticate (
292296 server_uri:: URIs.URI ;
293297 force:: Bool , maxcount:: Integer , hook:: Union{Base.Callable, Nothing} ,
294- project_uuid :: Union{UUID, Nothing} ,
298+ project_id :: Union{UUID, Nothing} ,
295299)
296300 isnothing (hook) || PkgAuthentication. register_open_browser_hook (hook)
297301 try
298302 # _authenticate either returns a valid token, or throws
299303 auth_toml = _authenticate_retry (string (server_uri), 1 ; force, maxcount)
300304 # Note: _authentication may throw, which gets passed on to the user
301- _authentication (server_uri; project_uuid , auth_toml... )
305+ _authentication (server_uri; project_id , auth_toml... )
302306 finally
303307 isnothing (hook) || PkgAuthentication. clear_open_browser_hook ()
304308 end
@@ -371,7 +375,7 @@ function _authentication(
371375 email:: Union{AbstractString, Nothing} = nothing ,
372376 username:: Union{AbstractString, Nothing} = nothing ,
373377 tokenpath:: Union{AbstractString, Nothing} = nothing ,
374- project_uuid :: Union{UUID, Nothing} = nothing ,
378+ project_id :: Union{UUID, Nothing} = nothing ,
375379)
376380 # If something goes badly wrong in _get_api_information, it may throw. We won't really
377381 # be able to proceed, since we do not know what JuliaHub APIs to use, so we need to
@@ -409,12 +413,12 @@ function _authentication(
409413 end
410414 return Authentication (
411415 server, api. api_version, username, token;
412- email, expires, tokenpath, project_uuid ,
416+ email, expires, tokenpath, project_id ,
413417 )
414418end
415419_authentication (server:: AbstractString ; kwargs... ) = _authentication (URIs. URI (server); kwargs... )
416420
417- function _normalize_project (
421+ function _juliahub_project (
418422 project:: Union{AbstractString, UUIDs.UUID, Nothing, Missing}
419423):: Union{UUID, Nothing}
420424 if ismissing (project)
@@ -426,7 +430,7 @@ function _normalize_project(
426430 return project
427431 elseif isa (project, AbstractString)
428432 project_uuid = tryparse (UUIDs. UUID, project)
429- if isnothing (project )
433+ if isnothing (project_uuid )
430434 throw (
431435 ArgumentError (
432436 " Invalid project_id passed to Authentication() - not a UUID: $(project) "
@@ -476,7 +480,8 @@ The `force`, `maxcount` and `hook` are relevant for interactive authentication,
476480same way as in the [`authenticate`](@ref) function.
477481
478482This is mostly meant to be used to re-acquire authentication tokens in long-running sessions, where
479- the initial authentication token may have expired.
483+ the initial authentication token may have expired. If the original `auth` object was authenticated
484+ in the context of a project (i.e. `.project_id` is set), the project association will be retained.
480485
481486As [`Authentication`](@ref) objects are mutable, the token will be updated in all contexts
482487where the reference to the [`Authentication`](@ref) has been passed to.
@@ -534,7 +539,7 @@ function reauthenticate!(
534539 end
535540 end
536541 @debug " reauthenticate! -- calling PkgAuthentication" auth. server
537- new_auth = _authenticate (auth. server; force, maxcount, hook)
542+ new_auth = _authenticate (auth. server; force, maxcount, hook, project_id = auth . project_id )
538543 if new_auth. username != auth. username
539544 throw (
540545 AuthenticationError (
0 commit comments