-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
handler_warden.go
44 lines (35 loc) · 1005 Bytes
/
handler_warden.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
42
43
44
package cli
import (
"encoding/json"
"fmt"
"github.com/ory-am/hydra/config"
"github.com/ory-am/hydra/oauth2"
"github.com/ory-am/hydra/pkg"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type WardenHandler struct {
Config *config.Config
M *oauth2.HTTPIntrospector
}
func newWardenHandler(c *config.Config) *WardenHandler {
return &WardenHandler{
Config: c,
M: &oauth2.HTTPIntrospector{},
}
}
func (h *WardenHandler) IsAuthorized(cmd *cobra.Command, args []string) {
h.M.Dry, _ = cmd.Flags().GetBool("dry")
h.M.Client = h.Config.OAuth2Client(cmd)
h.M.Endpoint = h.Config.Resolve("/connections")
if len(args) != 1 {
fmt.Print(cmd.UsageString())
return
}
scopes, _ := cmd.Flags().GetStringSlice("scopes")
res, err := h.M.IntrospectToken(context.Background(), args[0], scopes...)
pkg.Must(err, "Could not validate token: %s", err)
out, err := json.MarshalIndent(res, "", "\t")
pkg.Must(err, "Could not prettify token: %s", err)
fmt.Printf("%s\n", out)
}