forked from Tecsisa/dex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_client.go
54 lines (45 loc) · 1.17 KB
/
command_client.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
45
46
47
48
49
50
51
52
53
54
package main
import (
"net/url"
"github.com/coreos/go-oidc/oidc"
"github.com/spf13/cobra"
)
var (
cmdNewClient = &cobra.Command{
Use: "new-client",
Short: "Create a new client with one or more redirect URLs.",
Long: "Create a new client with one or more redirect URLs,",
Example: ` dexctl new-client --db-url=${DB_URL} 'https://example.com/callback'`,
Run: wrapRun(runNewClient),
}
)
func init() {
rootCmd.AddCommand(cmdNewClient)
}
func runNewClient(cmd *cobra.Command, args []string) int {
if len(args) < 1 {
stderr("Provide at least one redirect URL.")
return 2
}
redirectURLs := make([]url.URL, len(args))
for i, ua := range args {
u, err := url.Parse(ua)
if err != nil {
stderr("Malformed URL %q: %v", ua, err)
return 1
}
redirectURLs[i] = *u
}
cc, err := getDriver().NewClient(oidc.ClientMetadata{RedirectURIs: redirectURLs})
if err != nil {
stderr("Failed creating new client: %v", err)
return 1
}
stdout("# Added new client:")
stdout("DEX_APP_CLIENT_ID=%s", cc.ID)
stdout("DEX_APP_CLIENT_SECRET=%s", cc.Secret)
for i, u := range redirectURLs {
stdout("DEX_APP_REDIRECTURL_%d=%s", i, u.String())
}
return 0
}