|
1 | 1 | # PkgAuthentication |
2 | 2 |
|
3 | | -Authentication to private Julia package servers |
| 3 | +Interactive browser-based authentication to private Julia Pkg servers. |
4 | 4 |
|
| 5 | +## Setup |
| 6 | + |
| 7 | +#### Step 1: Make sure that PkgAuthentication.jl is installed in the default global Julia package environment (`v1.x`) |
| 8 | + |
| 9 | +```julia |
| 10 | +julia> delete!(ENV, "JULIA_PKG_SERVER") |
| 11 | + |
| 12 | +julia> import Pkg |
| 13 | + |
| 14 | +julia> Pkg.activate("v$(VERSION.major).$(VERSION.minor)"; shared = true) |
| 15 | + |
| 16 | +julia> Pkg.add("PkgAuthentication") |
5 | 17 | ``` |
6 | | - authenticate(pkgserver) |
7 | 18 |
|
8 | | -Starts browser based pkg-server authentication (blocking). |
| 19 | +#### Step 2: Set the `JULIA_PKG_SERVER` environment variable |
9 | 20 |
|
10 | | -`pkgserver` must be a URL pointing to a server that provides the `/pkgserver/challenge`, |
11 | | -`/pkgserver/response`, and `/pkgserver/claimtoken` endpoints. |
| 21 | +One easy way to set the `JULIA_PKG_SERVER` environment variable is to add the following |
| 22 | +line to your [`startup.jl`](https://docs.julialang.org/en/v1/manual/getting-started/) file: |
| 23 | + |
| 24 | +```julia |
| 25 | +ENV["JULIA_PKG_SERVER"] = "my-pkg-server.example.com" |
12 | 26 | ``` |
13 | 27 |
|
14 | | -## Installation |
15 | | -1. Make sure PkgAuthentication.jl is part of the default Julia environment. |
16 | | -2. Put the following into your `startup.jl` to enable authentication for server as configured in JULIA_PKG_SERVER environment variable. |
| 28 | +#### Step 3: Put the following snippet into your [`startup.jl`](https://docs.julialang.org/en/v1/manual/getting-started/) file |
| 29 | + |
17 | 30 | ```julia |
18 | 31 | # create a new anonymous module for the init code to not pollute the global namespace |
19 | 32 | Base.eval(Module(), quote |
20 | | - using PkgAuthentication |
21 | | - PkgAuthentication.install() |
| 33 | + import PkgAuthentication |
| 34 | + PkgAuthentication.install(); |
22 | 35 | end) |
23 | 36 | ``` |
24 | 37 |
|
| 38 | +With the above snippet, Pkg will automatically prompt you when you need to authenticate. |
| 39 | + |
| 40 | +However, if you want to authenticate immediately (instead of waiting until the first |
| 41 | +Pkg operation that needs authentication), you can do so as follows. First, make |
| 42 | +sure that you have completed steps 1, 2, and 3 above. Then, open the Julia REPL |
| 43 | +and run the following: |
| 44 | + |
| 45 | +```julia |
| 46 | +julia> import PkgAuthentication |
| 47 | + |
| 48 | +julia> PkgAuthentication.authenticate(); |
| 49 | +``` |
| 50 | + |
| 51 | +## Adding new registries |
| 52 | + |
| 53 | +If you are using this private Pkg server for the first time, you probably want to |
| 54 | +make sure that you add any private registries that might be served by this Pkg server. |
| 55 | + |
| 56 | +First, make sure that you have completed steps 1, 2, and 3 above. Then, open the |
| 57 | +Julia REPL and run the following: |
| 58 | + |
| 59 | +```julia |
| 60 | +julia> import Pkg |
| 61 | + |
| 62 | +julia> Pkg.Registry.add() |
| 63 | + |
| 64 | +julia> Pkg.Registry.update() |
| 65 | +``` |
| 66 | + |
25 | 67 | ## Implementation |
26 | 68 |
|
27 | 69 | Authentication is implemented with the following state machine: |
28 | 70 |
|
29 | | - |
| 71 | + |
0 commit comments