Save server specific login tokens in server config #2752
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Changes
These changes only impact the
spacetime
CLI.Currently, if a user is explicitly logging into a server using the
spacetime login --server-issued-login <server name>
or less directly by indicatingN
to theYou are not logged in. Would you like to log in with spacetimedb.com?
prompt, a JWT is created that is only valid for that specific server. Since the currentcli.toml
only supports a singlespacetimedb-token
at the root of the config, this quickly leads to collisions and attempts tospacetime publish
or performance other actions with tokens that are invalid if you are using multiple servers.This change will store a
spacetimedb-token
value in the associated server config section in thecli.toml
file. Here are the impacts to specific commands:spacetime login --server-issued-login <server name>
This command will store the generated JWT in the
cli.toml
section associated with that server. If a token is present already, it will give the existingYou are already logged in.
message, ignoring thespacetimedb-token
value at the root config if present.spacetime login show --server
A new flag has been introduced to this command to display the identity of the token stored for the provided server. If the server name is provided, the command will additionally display the name in the output. Example:
spacetime logout
This command will additionally delete all server
spacetimedb-token
values stored. This might be a bit harsh, but the intention ofspacetime logout
before was clearly remove all tokens and authentication, so this seemed most safe. Alternatively, we could only remove the root tokens and leave the server specific tokens intact and introduce a--server
flag to log out of the specific server, but this seemed more consistent.spacetime publish
/spacetime sql
/spacetime logs
/ etc.Any command that might have a path to force the user to log in to the server directly as a result of #2158 has the possibility of creating a JWT that will be stored as part of the provided (or default) server config if the user indicates they want to log in directly.
Unlike the above mentioned
spacetime login show
command, these will fall back to the rootspacetimedb-token
value. This is to handle backwards compatibility for users who have managed localhost JWTs already and would expect that functionality to persist, as well as to support centrally authoritative tokens like those generated by auth.spacetimedb.com or custom auth providers.spacetime server edit
This command is not impacted by this change. If you have a
spacetimedb-token
value associated with the server, it will get carried along if present.API and ABI breaking changes
None
Expected complexity level and risk
2
Testing