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): add auth command (#11004) #12885

Closed
wants to merge 2 commits into from

Conversation

elasticspoon
Copy link
Contributor

@elasticspoon elasticspoon commented Apr 7, 2024

Fixes #11004 (partially)

Creates the command coder auth for authentication purposes.

coder auth has 3 sub-commands login, status and token. Currently the sub-commands make 2 requests to the server: validation of the user and an additional command for sub-command info (token info, etc.)

coder auth status and coder auth token commands return an error if the user is not authenticated when they are called.

$ > coder auth status
Encountered an error running "coder auth status", see "coder auth status --help" for more information
error: You are not logged in. Try logging in using 'coder login <url>'.
exit status 1

coder auth

Just returns the help message.

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 status
Hello there, admin! You're authenticated at http://localhost:8080.

Additional info that is available from the current requests and could be shown:

  • ID
  • Username
  • AvatarURL
  • Name
  • Email
  • CreatedAt
  • LastSeenAt
  • Status
  • LoginType
  • ThemePreference
  • OrganizationIDs
  • Roles

coder auth token

Informs the user of their token string and the expiration time of the token. (Maybe coder auth session is a better name or alias?)

$ > coder auth token
Your session token 'DqSDeIXhgx-ABpLuIJ5PnLJjtvdUwmRK5' expires at 2024-04-13 18:08:59.278587 -0400 EDT.

Additional info that is available from the current requests and could be shown:

  • ID
  • UserID
  • LastUsed
  • ExpiresAt
  • CreatedAt
  • UpdatedAt
  • LoginType
  • Scope
  • TokenName
  • LifetimeSeconds

@cdr-bot cdr-bot bot added the community Pull Requests created by the community. label 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.
@elasticspoon elasticspoon changed the title feat(cli): add auth command feat(cli): add auth command (#11004) Apr 7, 2024
@elasticspoon elasticspoon marked this pull request as ready for review April 7, 2024 00:23
@matifali matifali requested review from ammario and sreya April 7, 2024 12:08
@ammario ammario requested review from mafredri and removed request for sreya and ammario April 11, 2024 17:29
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed when the user provides --token or the env, this might lead to some confusion as to where auth status originates from. It might be good to show "source" here, i.e. either it's from config, env or flag.

cli/auth.go Outdated Show resolved Hide resolved
cli/auth.go Outdated Show resolved Hide resolved
cli/auth.go Outdated Show resolved Hide resolved
cli/auth.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the stale This issue is like stale bread. label Apr 23, 2024
@matifali
Copy link
Collaborator

Hi @elasticspoon could you address review suggestions so the PR doesn't stale and close. Thank you for the contribution. :)

Change language in commands
Humanize session token remaining time
Inline auth middleware
@github-actions github-actions bot removed the stale This issue is like stale bread. label Apr 25, 2024
@elasticspoon
Copy link
Contributor Author

@matifali @mafredri Missed that this got reviewed, addressed both reviews.

@github-actions github-actions bot added the stale This issue is like stale bread. label May 3, 2024
@matifali matifali removed the stale This issue is like stale bread. label May 5, 2024
@github-actions github-actions bot added the stale This issue is like stale bread. label May 13, 2024
@github-actions github-actions bot closed this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Pull Requests created by the community. stale This issue is like stale bread.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cli): print a warning if user is already authenticated
3 participants