feat: CLI authentication — login, token storage, auto-refresh

Open
#86 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
go

Research direction

Start by reviewing the previous auth/oidc package referenced in salt evolution PR #85 and the integration points in salt/cli. Define how LoginCmd, LogoutCmd, Token, Client, secure token storage, refresh, and the PKCE flow fit together. Done means the five listed components are implemented as a usable CLI authentication package.

Written by the indexing model from the issue text.

Description

Context

The current auth/oidc package provides only the OIDC/PKCE browser flow for token acquisition. It's incomplete — no token storage, no refresh, no HTTP client integration. No raystack project uses it.

Meanwhile, every raystack CLI (frontier, compass, guardian) connects to APIs without authentication, which only works in development/trusted environments. Production APIs require auth, and CLIs have no way to authenticate.

Proposed solution

A complete CLI auth package following the pattern of gh auth login, gcloud auth login, and terraform login:

// Login — opens browser, does OIDC, stores token
auth.Login(ctx, auth.Config{
    Issuer:       "https://accounts.google.com",
    ClientID:     "...",
    RedirectURL:  "http://localhost:5454",
})

// Token — reads stored token, refreshes if expired
token, err := auth.Token(ctx)

// Client — returns http.Client that auto-attaches the token
client := auth.Client(ctx)
Components
  1. Token acquisition — browser-based OIDC with PKCE (existing code from dropped auth/oidc)
  2. Token storage — secure local storage at ~/.config/raystack/<app>/token.json
  3. Token refresh — auto-refresh expired tokens using refresh_token
  4. HTTP clienthttp.RoundTripper that reads stored token and attaches to requests
  5. CLI commandsLoginCmd() and LogoutCmd() for easy integration with cli.Execute()
Integration with salt/cli
cli.Execute(
    cli.Name("frontier"),
    cli.Commands(
        auth.LoginCmd(authConfig),
        auth.LogoutCmd(),
        userCmd, groupCmd,
    ),
)

// In commands:
func newListCmd() *cobra.Command {
    return &cobra.Command{
        RunE: func(cmd *cobra.Command, args []string) error {
            client := auth.Client(cmd)
            // make authenticated API calls
        },
    }
}
References
Dominant language
Go
Stars
14
Forks
8
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from raystack/salt

All issues in raystack/salt

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.