Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)

Expand Down
41 changes: 41 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Long: `Display information about the currently stored authentication token.
Long: `Display information about the stored authentication tokens.


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",
Expand Down Expand Up @@ -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)
Expand Down