diff --git a/README.md b/README.md index e896a05..a5d60a0 100644 --- a/README.md +++ b/README.md @@ -140,6 +140,7 @@ go build -o jh . - `jh auth refresh` - Refresh authentication token - `jh auth status` - Show authentication status - `jh auth env` - Print environment variables for authentication +- `jh auth list` - Print the current auth token information ### Dataset Management (`jh dataset`) diff --git a/auth.go b/auth.go index f8e2528..9dfd629 100644 --- a/auth.go +++ b/auth.go @@ -421,3 +421,44 @@ func authEnvCommand() error { return nil } + +// authListCommand lists the current stored authentication token +func authListCommand() error { + token, err := readStoredToken() + if err != nil { + fmt.Println("No authentication token found.") + fmt.Println("Run 'jh auth login' to authenticate with JuliaHub.") + return nil + } + + expired, _ := isTokenExpired(token.AccessToken, token.ExpiresIn) + status := "Valid" + if expired { + status = "Expired" + } + + fmt.Println("Authentication Token:") + fmt.Printf(" Server: %s\n", token.Server) + fmt.Printf(" Status: %s\n", status) + + if token.Name != "" { + fmt.Printf(" Name: %s\n", token.Name) + } + if token.Email != "" { + fmt.Printf(" Email: %s\n", token.Email) + } + + // Show token expiration if available + if token.IDToken != "" { + if claims, err := decodeJWT(token.IDToken); err == nil { + if claims.ExpiresAt > 0 { + expireTime := time.Unix(claims.ExpiresAt, 0) + fmt.Printf(" Expires: %s\n", expireTime.Format(time.RFC3339)) + } + } + } + + fmt.Printf(" Has Refresh Token: %t\n", token.RefreshToken != "") + + return nil +} diff --git a/main.go b/main.go index 71b31c2..5ad569a 100644 --- a/main.go +++ b/main.go @@ -318,6 +318,28 @@ environment variables that can be used by other tools or scripts.`, }, } +var authListCmd = &cobra.Command{ + Use: "list", + Short: "List stored authentication token information", + Long: `Display information about the currently stored authentication token. + +This command shows: +- Server name +- User information (name and email) +- Token validity status (valid or expired) +- Token expiration time +- Refresh token availability + +This provides a quick summary of your current authentication status.`, + Example: " jh auth list", + Run: func(cmd *cobra.Command, args []string) { + if err := authListCommand(); err != nil { + fmt.Printf("Failed to list authentication token: %v\n", err) + os.Exit(1) + } + }, +} + var jobCmd = &cobra.Command{ Use: "job", Short: "Job management commands", @@ -991,7 +1013,7 @@ func init() { pullCmd.Flags().StringP("server", "s", "juliahub.com", "JuliaHub server") updateCmd.Flags().Bool("force", false, "Force update even if current version is newer than latest release") - authCmd.AddCommand(authLoginCmd, authRefreshCmd, authStatusCmd, authEnvCmd) + authCmd.AddCommand(authLoginCmd, authRefreshCmd, authStatusCmd, authEnvCmd, authListCmd) jobCmd.AddCommand(jobListCmd, jobStartCmd) datasetCmd.AddCommand(datasetListCmd, datasetDownloadCmd, datasetUploadCmd, datasetStatusCmd) projectCmd.AddCommand(projectListCmd)