| 110 | } |
| 111 | |
| 112 | func revokeAllTokensCmd() *cobra.Command { |
| 113 | cmd := &cobra.Command{ |
| 114 | Use: "revoke-all-tokens --before [epoch]", |
| 115 | Short: "Revoke all tokens", |
| 116 | Long: heredoc.Doc(` |
| 117 | This command revokes ALL tokens for all users of an application. |
| 118 | This should be used with caution as it will expire every user’s token, |
| 119 | regardless of whether the token has an iat claim. |
| 120 | `), |
| 121 | Example: heredoc.Doc(` |
| 122 | # Revoke all tokens for the default app, from now |
| 123 | $ stream-cli chat revoke-all-tokens |
| 124 | |
| 125 | # Revoke all tokens for the test app, before 2019-01-01 |
| 126 | $ stream-cli chat revoke-all-tokens --before 1546300800 --app test |
| 127 | `), |
| 128 | RunE: func(cmd *cobra.Command, args []string) error { |
| 129 | c, err := config.GetConfig(cmd).GetClient(cmd) |
| 130 | if err != nil { |
| 131 | return err |
| 132 | } |
| 133 | |
| 134 | before, _ := cmd.Flags().GetInt64("before") |
| 135 | if before == 0 { |
| 136 | before = time.Now().Unix() |
| 137 | } |
| 138 | beforeDate := time.Unix(before, 0) |
| 139 | |
| 140 | _, err = c.RevokeTokens(cmd.Context(), &beforeDate) |
| 141 | if err != nil { |
| 142 | return err |
| 143 | } |
| 144 | |
| 145 | cmd.Println("Successfully revoked all tokens.") |
| 146 | return nil |
| 147 | }, |
| 148 | } |
| 149 | |
| 150 | fl := cmd.Flags() |
| 151 | fl.Int64P("before", "b", 0, "[optional] The epoch timestamp before which tokens should be revoked. Defaults to now.") |
| 152 | |
| 153 | return cmd |
| 154 | } |