Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): print a warning if user is already authenticated #11004

Open
Tracked by #10759
phorcys420 opened this issue Dec 2, 2023 · 2 comments
Open
Tracked by #10759

feat(cli): print a warning if user is already authenticated #11004

phorcys420 opened this issue Dec 2, 2023 · 2 comments
Labels
cli Area: CLI feature Something we don't have yet

Comments

@phorcys420
Copy link
Contributor

Currently, the CLI lets you log in as many times as you wish even though you're already logged in.
I think the CLI shouldn't let you do that or at least tell you that you're already logged in as a "warning".

Something like, "your Coder CLI is already authenticated as phorcys @ https://coder.domain.tld".

This occurs to me whenever I go back to use coder on a machine I don't use frequently, I never know if I'm logged in or not.
I think there could also be a coder whoami command letting you know what user you're connected with, on what instance and how long your authentication will be valid.

I would like this because I go between my own instance and the dogfood instance, that feature would be pretty handy.


PS C:\Users\Phorcys> coder login https://coder.domain.tld
Your browser has been opened to visit:

        https://coder.domain.tld/cli-auth

> Paste your token here: [...]
> Welcome to Coder, phorcys! You're authenticated.
PS C:\Users\Phorcys> coder login https://coder.domain.tld
Your browser has been opened to visit:

        https://coder.domain.tld/cli-auth

> Paste your token here: [...]
> Welcome to Coder, phorcys! You're authenticated.

Coder v2.4.0+d19a762


cc: @matifali

@cdr-bot cdr-bot bot added the feature Something we don't have yet label Dec 2, 2023
@mafredri
Copy link
Member

mafredri commented Dec 3, 2023

I'm pro-warning (You're already authenticated as foobar, are you sure you want to re-authenticate?) because there will be cases where you might want to auth as another user, or some such. Also coder whoami could be coder auth status.

@matifali
Copy link
Collaborator

matifali commented Dec 3, 2023

@mafredri yes
I have seen this format with other CLIs, where login is coder auth login and the status is coder auth status, and to get the current token coder auth token.

We still should keep coder login for backward compatibility.

@matifali matifali changed the title feat(cli): don't let the user log in indefinitely feat(cli): print a warning if user is already authenticated Dec 3, 2023
@matifali matifali added the cli Area: CLI label Dec 11, 2023
elasticspoon added a commit to elasticspoon/coder that referenced this issue Apr 7, 2024
)

Prompt the user if they want to re-authenticate if they run
`coder login` when already authenticated.

Does not apply if they provided a token via flag or ENV
variable. A new token should be generated an stored in that situation
unless the `--use-token-as-session` flag was also used.

fix(cli): prompt user on login attempt with invalid ENV token

Fixes issue where if invalid token was set as ENV
variable a user would be unable to login until the ENV
variable was cleared.

User will now be informed that the token is invalid and
prompted to login normally.
elasticspoon added a commit to elasticspoon/coder that referenced this issue Apr 7, 2024
Adds `coder auth` command with 3 sub-commands: `coder auth token`,
`coder auth status` and `coder auth login`.

`coder auth login`: This is the same command as `coder login`.

`coder auth status`: Informs the user about their authentication
status. It may make sense for this to not show an error
if called when user is not logged in.

`coder auth token`: Informs the user of their token string
and the expiration time of the token.

All the commands use a middleware to check that the user is
authenticated and will return an error if the user is not. They also
make at most 2 API calls.

The commands have additional values that could be shown but are not with
this implementation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Area: CLI feature Something we don't have yet
Projects
None yet
3 participants