forked from ory/hydra
/
handler_warden.go
44 lines (35 loc) · 987 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/pkg"
"github.com/ory-am/hydra/warden"
"github.com/spf13/cobra"
"golang.org/x/net/context"
)
type WardenHandler struct {
Config *config.Config
M *warden.HTTPWarden
}
func newWardenHandler(c *config.Config) *WardenHandler {
return &WardenHandler{
Config: c,
M: &warden.HTTPWarden{},
}
}
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.TokenValid(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 marshall keys: %s", err)
fmt.Printf("%s\n", out)
}