-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_introspect_token.go
41 lines (34 loc) · 1.09 KB
/
cmd_introspect_token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright © 2022 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package cmd
import (
"strings"
"github.com/ory/hydra/v2/cmd/cliclient"
"github.com/ory/x/cmdx"
"github.com/ory/x/flagx"
"github.com/spf13/cobra"
)
func NewIntrospectTokenCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "token the-token",
Args: cobra.ExactArgs(1),
Example: `{{ .CommandPath }} AYjcyMzY3ZDhiNmJkNTY --project 32197be3-8e57-4009-becd-9d38dbde129c`,
Short: "Introspect an OAuth 2.0 Access or Refresh Token",
RunE: func(cmd *cobra.Command, args []string) error {
client, _, err := cliclient.NewClient(cmd)
if err != nil {
return err
}
result, _, err := client.OAuth2API.IntrospectOAuth2Token(cmd.Context()).
Token(args[0]).
Scope(strings.Join(flagx.MustGetStringSlice(cmd, "scope"), " ")).Execute() //nolint:bodyclose
if err != nil {
return cmdx.PrintOpenAPIError(cmd, err)
}
cmdx.PrintRow(cmd, outputOAuth2TokenIntrospection(*result))
return nil
},
}
cmd.Flags().StringSlice("scope", []string{}, "Additionally check if the scope was granted.")
return cmd
}