2015-08-18 05:57:27 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
"github.com/coreos/go-oidc/oidc"
|
2015-12-29 05:25:11 +05:30
|
|
|
"github.com/spf13/cobra"
|
2015-08-18 05:57:27 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-12-29 05:25:11 +05:30
|
|
|
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),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2015-12-29 05:25:11 +05:30
|
|
|
rootCmd.AddCommand(cmdNewClient)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
2015-12-29 05:25:11 +05:30
|
|
|
func runNewClient(cmd *cobra.Command, args []string) int {
|
2015-08-18 05:57:27 +05:30
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
cc, err := getDriver().NewClient(oidc.ClientMetadata{RedirectURIs: redirectURLs})
|
2015-08-18 05:57:27 +05:30
|
|
|
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 {
|
2015-08-24 20:50:04 +05:30
|
|
|
stdout("DEX_APP_REDIRECTURL_%d=%s", i, u.String())
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|