-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_warden.go
43 lines (34 loc) · 902 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
package cli
import (
"context"
"encoding/json"
"fmt"
"github.com/ory/hydra/config"
"github.com/ory/hydra/oauth2"
"github.com/ory/hydra/pkg"
"github.com/spf13/cobra"
)
type WardenHandler struct {
Config *config.Config
}
func newWardenHandler(c *config.Config) *WardenHandler {
return &WardenHandler{
Config: c,
}
}
func (h *WardenHandler) IsAuthorized(cmd *cobra.Command, args []string) {
m := &oauth2.HTTPIntrospector{
Endpoint: h.Config.Resolve("/oauth2/introspect"),
Client: h.Config.OAuth2Client(cmd),
}
if len(args) != 1 {
fmt.Print(cmd.UsageString())
return
}
scopes, _ := cmd.Flags().GetStringSlice("scopes")
res, err := 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)
}