@@ -835,7 +835,7 @@ function open_browser(url::AbstractString)
835835end
836836
837837"""
838- install(server::AbstractString; maxcount = 3)
838+ install(server::AbstractString; maxcount = 3) -> PkgAuthentication.Uninstall
839839
840840Install Pkg authentication hooks for the Pkg server specified by `server`. Also
841841sets the `$(pkg_server_env_var_name) ` environment variable to `server`.
@@ -862,7 +862,7 @@ function install(server::AbstractString; maxcount::Integer=3)
862862end
863863
864864"""
865- install(; maxcount = 3)
865+ install(; maxcount = 3) -> PkgAuthentication.Uninstall
866866
867867Install Pkg authentication hooks for the Pkg server specified in the `$(pkg_server_env_var_name) `
868868environment variable.
@@ -872,6 +872,8 @@ must be set to the URL of a valid Pkg server.
872872
873873`maxcount` determines the number of retries.
874874
875+ You can call the returned object (no arguments) to uninstall the Pkg authentication hooks.
876+
875877!!! compat "Julia 1.4"
876878 Pkg authentication hooks require at least Julia 1.4. On earlier versions, this
877879 method will instead force authentication immediately.
@@ -880,8 +882,10 @@ must be set to the URL of a valid Pkg server.
880882
881883```julia
882884julia> PkgAuthentication.install()
885+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
883886
884887julia> PkgAuthentication.install(; maxcount = 5)
888+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
885889```
886890"""
887891function install (; maxcount:: Integer = 3 )
@@ -891,12 +895,15 @@ function install(; maxcount::Integer=3)
891895 _assert_pkg_server_env_var_is_set ()
892896 server = String (pkg_server ())
893897 auth_handler = generate_auth_handler (maxcount)
894- @static if PkgAuthentication. is_new_auth_mechanism ()
898+ uninstall_hook = @static if PkgAuthentication. is_new_auth_mechanism ()
895899 Pkg. PlatformEngines. register_auth_error_handler (server, auth_handler)
896900 else
897901 # old Julia versions don't support auth hooks, so let's authenticate now and be done with it
898902 authenticate (server)
903+ # the returned Uninstall will be a silent no-op
904+ nothing
899905 end
906+ return Uninstall (uninstall_hook)
900907end
901908
902909function generate_auth_handler (maxcount:: Integer )
@@ -921,6 +928,27 @@ function generate_auth_handler(maxcount::Integer)
921928 return auth_handler
922929end
923930
931+ """
932+ struct Uninstall
933+
934+ Wrapper around the closure returned by `Pkg.PlatformEngines.register_auth_error_handler`.
935+ Calling this object will remove the Pkg authentication hooks.
936+
937+ ```julia
938+ julia> uninstall = PkgAuthentication.install()
939+ PkgAuthentication.Uninstall (call this object to remove Pkg hooks)
940+
941+ julia> uninstall()
942+ ```
943+ """
944+ struct Uninstall
945+ f:: Union{Base.Callable, Nothing}
946+ end
947+ (c:: Uninstall )() = isnothing (c. f) ? nothing : c. f ()
948+ function Base. show (io:: IO , :: MIME"text/plain" , :: Uninstall )
949+ print (io, " PkgAuthentication.Uninstall (call this object to remove Pkg hooks)" )
950+ end
951+
924952include (" precompile.jl" )
925953
926954end # module
0 commit comments