diff --git a/cli/packages/cmd/user.go b/cli/packages/cmd/user.go index 6c7d54d46c..3b0970403e 100644 --- a/cli/packages/cmd/user.go +++ b/cli/packages/cmd/user.go @@ -114,6 +114,11 @@ var userGetTokenCmd = &cobra.Command{ loggedInUserDetails = util.EstablishUserLoginSession() } + plain, err := cmd.Flags().GetBool("plain") + if err != nil { + util.HandleError(err, "[infisical user get token]: Unable to get plain flag") + } + if err != nil { util.HandleError(err, "[infisical user get token]: Unable to get logged in user token") } @@ -135,8 +140,12 @@ var userGetTokenCmd = &cobra.Command{ util.HandleError(err, "[infisical user get token]: Unable to parse token payload") } - fmt.Println("Session ID:", tokenPayload.TokenVersionId) - fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken) + if plain { + fmt.Println(loggedInUserDetails.UserCredentials.JTWToken) + } else { + fmt.Println("Session ID:", tokenPayload.TokenVersionId) + fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken) + } }, } @@ -240,7 +249,10 @@ var domainCmd = &cobra.Command{ func init() { updateCmd.AddCommand(domainCmd) userCmd.AddCommand(updateCmd) + + userGetTokenCmd.Flags().Bool("plain", false, "print token without formatting") userGetCmd.AddCommand(userGetTokenCmd) + userCmd.AddCommand(userGetCmd) userCmd.AddCommand(switchCmd) rootCmd.AddCommand(userCmd) diff --git a/docs/cli/commands/user.mdx b/docs/cli/commands/user.mdx index 43a6111e1a..108b1f23b4 100644 --- a/docs/cli/commands/user.mdx +++ b/docs/cli/commands/user.mdx @@ -35,19 +35,40 @@ infisical user update domain Use this command to get your current Infisical access token and session information. This command requires you to be logged in. - The command will display: +The command will display: - - Your session ID - - Your full JWT access token +- Your session ID +- Your full JWT access token - ```bash - infisical user get token - ``` +```bash +infisical user get token +``` - Example output: +Example output: + +```bash +Session ID: abc123-xyz-456 +Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... +``` + +### Flags + + + Output only the JWT token without formatting (no session ID) + + Default value: `false` + + ```bash + # Example + infisical user get token --plain + ``` + + Example output: + + ```bash + eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... + ``` + + - ```bash - Session ID: abc123-xyz-456 - Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9... - ```