Compare commits

...

1 Commits

Author SHA1 Message Date
38c9242e5b misc: add plain support for user get token in CLI 2025-07-02 04:45:53 +08:00
2 changed files with 46 additions and 13 deletions

View File

@ -114,6 +114,11 @@ var userGetTokenCmd = &cobra.Command{
loggedInUserDetails = util.EstablishUserLoginSession() 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 { if err != nil {
util.HandleError(err, "[infisical user get token]: Unable to get logged in user token") 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") util.HandleError(err, "[infisical user get token]: Unable to parse token payload")
} }
if plain {
fmt.Println(loggedInUserDetails.UserCredentials.JTWToken)
} else {
fmt.Println("Session ID:", tokenPayload.TokenVersionId) fmt.Println("Session ID:", tokenPayload.TokenVersionId)
fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken) fmt.Println("Token:", loggedInUserDetails.UserCredentials.JTWToken)
}
}, },
} }
@ -240,7 +249,10 @@ var domainCmd = &cobra.Command{
func init() { func init() {
updateCmd.AddCommand(domainCmd) updateCmd.AddCommand(domainCmd)
userCmd.AddCommand(updateCmd) userCmd.AddCommand(updateCmd)
userGetTokenCmd.Flags().Bool("plain", false, "print token without formatting")
userGetCmd.AddCommand(userGetTokenCmd) userGetCmd.AddCommand(userGetTokenCmd)
userCmd.AddCommand(userGetCmd) userCmd.AddCommand(userGetCmd)
userCmd.AddCommand(switchCmd) userCmd.AddCommand(switchCmd)
rootCmd.AddCommand(userCmd) rootCmd.AddCommand(userCmd)

View File

@ -35,19 +35,40 @@ infisical user update domain
<Accordion title="infisical user get token"> <Accordion title="infisical user get token">
Use this command to get your current Infisical access token and session information. This command requires you to be logged in. 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 session ID
- Your full JWT access token - Your full JWT access token
```bash
infisical user get token
```
Example output:
```bash
Session ID: abc123-xyz-456
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```
### Flags
<Accordion title="--plain">
Output only the JWT token without formatting (no session ID)
Default value: `false`
```bash ```bash
infisical user get token # Example
infisical user get token --plain
``` ```
Example output: Example output:
```bash ```bash
Session ID: abc123-xyz-456 eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
``` ```
</Accordion>
</Accordion> </Accordion>