Skip to content

Commit b4b29d0

Browse files
committed
Support other nextstrain.org-like remotes
Adds support for other nextstrain.org-like remotes to the `nextstrain remote` family of commands, along with support for OIDC/OAuth2 authentication with them to the `nextstrain login` and related commands. Required IdP and client configuration for OIDC/OAuth2 is auto-discovered. One giant pile of changes, because I did not have time to go thru my typical editing and splitting process before going on leave. :/ Ah well. Related-to: <nextstrain/private#94>
1 parent dc957d5 commit b4b29d0

24 files changed

+1790
-620
lines changed

CHANGES.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,40 @@ This release drops support for Python versions 3.6 and 3.7 and adds support for
1919

2020
## Improvements
2121

22+
* The `nextstrain remote` family of commands now support alternative
23+
nextstrain.org-like remotes such as internal Nextstrain Groups Server
24+
instances and development instances of nextstrain.org. Authentication with
25+
these remotes is supported via `nextstrain login` and related commands.
26+
Remotes maintain their authentication alongside each other, e.g. you can be
27+
logged into nextstrain.org as well as an alternative nextstrain.org-like
28+
instance.
29+
30+
As an example, a Nextstrain Groups Server instance accessible at
31+
nextstrain.example.com could now be logged into and interacted with like so:
32+
33+
nextstrain login nextstrain.example.com
34+
nextstrain whoami nextstrain.example.com
35+
nextstrain remote ls nextstrain.example.com/groups/bedford-lab/
36+
37+
The default remote is still nextstrain.org.
38+
([#333](https://github.com/nextstrain/cli/pull/333))
39+
40+
* `nextstrain login` now performs authentication via a web browser by default
41+
(using OpenID Connect 1.0 and OAuth 2.0). The previously method of direct
42+
password entry is still used when a username is provided (e.g. with
43+
`--username` or `-u`). See `nextstrain login --help` for more information.
44+
([#333](https://github.com/nextstrain/cli/pull/333))
45+
2246
* `nextstrain remote upload` now skips gzip compression when uploading
2347
zstandard-compressed (`.zst`) files, matching its behaviour for other types
2448
of compressed files.
2549
([#330](https://github.com/nextstrain/cli/pull/330))
2650

27-
* Commands that may automatically open a web browser, e.g. `nextstrain view`,
28-
now respect the semi-conventional `NOBROWSER` environment variable to disable
29-
opening a browser. Set `NOBROWSER` to a non-empty value to disable automatic
30-
opening.
51+
* Commands that may automatically open a web browser, e.g. `nextstrain view` or
52+
`nextstrain login`, now respect the semi-conventional `NOBROWSER` environment
53+
variable to disable opening a browser. Set `NOBROWSER` to a non-empty value
54+
to disable automatic opening. When disabled, the URL to manually open will
55+
be shown.
3156
([#332](https://github.com/nextstrain/cli/pull/332))
3257

3358
* The error message emitted by the `nextstrain remote` family of commands when

doc/commands/authorization.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,35 @@ nextstrain authorization
1212

1313
.. code-block:: none
1414
15-
usage: nextstrain authorization [-h]
15+
usage: nextstrain authorization [-h] [<remote-url>]
1616
1717
18-
Produce an Authorization header appropriate for nextstrain.org's web API.
18+
Produce an Authorization header appropriate for the web API of nextstrain.org
19+
(and other remotes).
1920

2021
This is a development tool unnecessary for normal usage. It's useful for
21-
directly making API requests to nextstrain.org with `curl` or similar
22-
commands. For example::
22+
directly making API requests to nextstrain.org (and other remotes) with `curl`
23+
or similar commands. For example::
2324

2425
curl -si https://nextstrain.org/whoami \
2526
--header "Accept: application/json" \
2627
--header @<(nextstrain authorization)
2728

2829
Exits with an error if no one is logged in.
2930

31+
positional arguments
32+
====================
33+
34+
35+
36+
.. option:: <remote-url>
37+
38+
Remote URL for which to produce an Authorization header. Expects
39+
URLs like the remote source/destination URLs used by the
40+
`nextstrain remote` family of commands. Only the domain name
41+
(technically, the origin) of the URL is required/used, but a full
42+
URL may be specified.
43+
3044
options
3145
=======
3246

doc/commands/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ commands
7474

7575
.. option:: login
7676

77-
Log into Nextstrain.org. See :doc:`/commands/login`.
77+
Log into Nextstrain.org (and other remotes). See :doc:`/commands/login`.
7878

7979
.. option:: logout
8080

81-
Log out of Nextstrain.org. See :doc:`/commands/logout`.
81+
Log out of Nextstrain.org (and other remotes). See :doc:`/commands/logout`.
8282

8383
.. option:: whoami
8484

doc/commands/login.rst

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,37 @@ nextstrain login
1212

1313
.. code-block:: none
1414
15-
usage: nextstrain login [-h] [--username <name>] [--no-prompt] [--renew]
15+
usage: nextstrain login [-h] [--username <name>] [--no-prompt] [--renew] [<remote-url>]
1616
1717
18-
Log into Nextstrain.org and save credentials for later use.
18+
Log into Nextstrain.org (and other remotes) and save credentials for later use.
1919

20-
The first time you log in, you'll be prompted for your Nextstrain.org username
21-
and password. After that, locally-saved authentication tokens will be used and
22-
automatically renewed as needed when you run other `nextstrain` commands
23-
requiring log in. You can also re-run this `nextstrain login` command to force
24-
renewal if you want. You'll only be prompted for your username and password if
25-
the locally-saved tokens are unable to be renewed or missing entirely.
20+
The first time you log in to a remote you'll be prompted to authenticate via
21+
your web browser or, if you provide a username (e.g. with --username), for your
22+
Nextstrain.org password. After that, locally-saved authentication tokens will
23+
be used and automatically renewed as needed when you run other `nextstrain`
24+
commands requiring log in. You can also re-run this `nextstrain login` command
25+
to force renewal if you want. You'll only be prompted to reauthenticate (via
26+
your web browser or username/password) if the locally-saved tokens are unable
27+
to be renewed or missing entirely.
2628

27-
If you log out of Nextstrain.org on other devices/clients (like your web
28-
browser), you may be prompted to re-enter your username and password by this
29-
command sooner than usual.
29+
If you log out of Nextstrain.org (or other remotes) on other devices/clients
30+
(like your web browser), you may be prompted to reauthenticate by this command
31+
sooner than usual.
3032

31-
Your password itself is never saved locally.
33+
Your username and password themselves are never saved locally.
34+
35+
positional arguments
36+
====================
37+
38+
39+
40+
.. option:: <remote-url>
41+
42+
Remote URL to log in to, like the remote source/destination URLs
43+
used by the `nextstrain remote` family of commands. Only the
44+
domain name (technically, the origin) of the URL is required/used,
45+
but a full URL may be specified.
3246

3347
options
3448
=======
@@ -45,7 +59,7 @@ options
4559

4660
.. option:: --no-prompt
4761

48-
Never prompt for a username/password; succeed only if there are login credentials in the environment or existing valid/renewable tokens saved locally, otherwise error. Useful for scripting.
62+
Never prompt for authentication (via web browser or username/password); succeed only if there are login credentials in the environment or existing valid/renewable tokens saved locally, otherwise error. Useful for scripting.
4963

5064
.. option:: --renew
5165

@@ -62,4 +76,7 @@ of interactive input and/or command-line options:
6276
.. envvar:: NEXTSTRAIN_PASSWORD
6377

6478
Password for nextstrain.org user. Required if :option:`--no-prompt` is
65-
used without existing valid/renewable tokens.
79+
used without existing valid/renewable tokens.
80+
81+
If you want to suppress ever opening a web browser automatically, you
82+
may set the environment variable ``NOBROWSER=1``.

doc/commands/logout.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,29 @@ nextstrain logout
1212

1313
.. code-block:: none
1414
15-
usage: nextstrain logout [-h]
15+
usage: nextstrain logout [-h] [<remote-url>]
1616
1717
18-
Log out of Nextstrain.org by deleting locally-saved credentials.
18+
Log out of Nextstrain.org (and other remotes) by deleting locally-saved
19+
credentials.
1920

2021
The authentication tokens are removed but not invalidated, so if you used them
2122
outside of the `nextstrain` command, they will remain valid until they expire.
2223

2324
Other devices/clients (like your web browser) are not logged out of
24-
Nextstrain.org.
25+
Nextstrain.org (or other remotes).
26+
27+
positional arguments
28+
====================
29+
30+
31+
32+
.. option:: <remote-url>
33+
34+
Remote URL to log out of, like the remote source/destination URLs
35+
used by the `nextstrain remote` family of commands. Only the
36+
domain name (technically, the origin) of the URL is required/used,
37+
but a full URL may be specified.
2538

2639
options
2740
=======

doc/commands/whoami.rst

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,29 @@ nextstrain whoami
1212

1313
.. code-block:: none
1414
15-
usage: nextstrain whoami [-h]
15+
usage: nextstrain whoami [-h] [<remote-url>]
1616
1717
18-
Show information about the logged-in user.
18+
Show information about the logged-in user for Nextstrain.org (and other
19+
remotes).
1920

20-
The username, email address, and Nextstrain Groups memberships of the currently
21-
logged-in user are shown.
21+
The username, email address (if available), and Nextstrain Groups memberships
22+
of the currently logged-in user are shown.
2223

2324
Exits with an error if no one is logged in.
2425

26+
positional arguments
27+
====================
28+
29+
30+
31+
.. option:: <remote-url>
32+
33+
Remote URL for which to show the logged-in user. Expects URLs like
34+
the remote source/destination URLs used by the `nextstrain remote`
35+
family of commands. Only the domain name (technically, the origin)
36+
of the URL is required/used, but a full URL may be specified.
37+
2538
options
2639
=======
2740

doc/development.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@ resources from our ["testing" configuration][], you can configure `nextstrain`
5959
with the same, e.g.:
6060

6161
export NEXTSTRAIN_DOT_ORG=http://localhost:5000
62-
export NEXTSTRAIN_COGNITO_USER_POOL_ID="$(jq -r .COGNITO_USER_POOL_ID ../nextstrain.org/env/testing/config.json)"
63-
export NEXTSTRAIN_COGNITO_CLI_CLIENT_ID="$(jq -r .OAUTH2_CLI_CLIENT_ID ../nextstrain.org/env/testing/config.json)"
6462

6563
nextstrain login
6664
nextstrain whoami
6765
nextstrain remote ls groups/test-private
6866

67+
Most of the times the above is not necessary, however, as you can specify the
68+
local remote explicitly instead of pretending it's nextstrain.org, e.g.:
69+
70+
nextstrain remote ls http://localhost:5000/groups/test
71+
72+
nextstrain login http://localhost:5000
73+
nextstrain whoami http://localhost:5000
74+
nextstrain remote ls http://localhost:5000/groups/test-private
75+
76+
Setting `NEXTSTRAIN_DOT_ORG` is mostly useful when testing the default-remote
77+
code paths themselves.
78+
6979
## Releasing
7080

7181
New releases are made frequently and tagged in git using a [_signed_ tag][].

0 commit comments

Comments
 (0)