diff --git a/cmd/root.go b/cmd/root.go index 2fb651c..bf1d7c6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,7 +31,6 @@ var rootCmd = &cobra.Command{ } func Execute() { - initialize() if err := rootCmd.Execute(); err != nil { fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err) os.Exit(1) @@ -39,14 +38,19 @@ func Execute() { } func init() { - rootCmd.PersistentFlags().BoolVarP(&config.Options.Verbose, "verbose", "v", false, "set the verbose flag") + cobra.OnInitialize(initialize) + rootCmd.PersistentFlags().BoolVarP(&config.Options.Verbose, "verbose", "v", config.Options.Verbose, "set the verbose flag") rootCmd.PersistentFlags().StringVarP(&confPath, "config", "c", "", "set the config path") rootCmd.PersistentFlags().StringVar(&config.Options.CachePath, "cache", "", "set the cache path") } func initialize() { initConfig() - initEnv() + err := initEnv() + if err != nil { + fmt.Println(err) + fmt.Println("WARNING: Ignoring environment variables with errors.") + } } func initConfig() { diff --git a/cmd/serve.go b/cmd/serve.go index 2f35d18..5b8164f 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -36,10 +36,10 @@ var serveCmd = &cobra.Command{ func init() { serveCmd.Flags().StringVar(&config.Server.Issuer.Host, "host", "127.0.0.1", "set the identity provider host") - serveCmd.Flags().IntVar(&config.Server.Issuer.Port, "port", 3332, "set the identity provider port") - serveCmd.Flags().StringVar(&endpoints.Authorization, "endpoints.authorization", "", "set the authorization endpoint for the identity provider") - serveCmd.Flags().StringVar(&endpoints.Token, "endpoints.token", "", "set the token endpoint for the identity provider") - serveCmd.Flags().StringVar(&endpoints.JwksUri, "endpoints.jwks_uri", "", "set the JWKS endpoints for the identity provider") + serveCmd.Flags().IntVar(&config.Server.Issuer.Port, "port", config.Server.Issuer.Port, "set the identity provider port") + serveCmd.Flags().StringVar(&endpoints.Authorization, "endpoints.authorization", endpoints.Authorization, "set the authorization endpoint for the identity provider") + serveCmd.Flags().StringVar(&endpoints.Token, "endpoints.token", endpoints.Token, "set the token endpoint for the identity provider") + serveCmd.Flags().StringVar(&endpoints.JwksUri, "endpoints.jwks_uri", endpoints.JwksUri, "set the JWKS endpoints for the identity provider") rootCmd.AddCommand(serveCmd) } diff --git a/internal/config.go b/internal/config.go index 9108ac1..67742bc 100644 --- a/internal/config.go +++ b/internal/config.go @@ -79,6 +79,8 @@ func NewConfig() Config { Host: "127.0.0.1", Port: 3333, Issuer: server.IdentityProviderServer{ + Host: "127.0.0.1", + Port: 3332, Endpoints: oidc.Endpoints{ Authorization: "", Token: "", diff --git a/internal/oidc/oidc.go b/internal/oidc/oidc.go index f52e0c4..f7e4f96 100644 --- a/internal/oidc/oidc.go +++ b/internal/oidc/oidc.go @@ -75,6 +75,43 @@ func NewIdentityProvider() *IdentityProvider { return p } +func (p *IdentityProvider) NewEndpoints() *Endpoints { + return &Endpoints{ + Authorization: p.Issuer + "/oauth/authorize", + Token: p.Issuer + "/oauth/token", + Revocation: p.Issuer + "/oauth/revocation", + Introspection: p.Issuer + "/oauth/introspect", + UserInfo: p.Issuer + "/oauth/userinfo", + JwksUri: p.Issuer + "/oauth/discovery/keys", + } +} + +func (p *IdentityProvider) NewSupported() *Supported { + return &Supported{ + ResponseTypes: []string{"code"}, + ResponseModes: []string{"query"}, + GrantTypes: []string{ + "authorization_code", + "client_credentials", + "refresh_token", + }, + TokenEndpointAuthMethods: []string{ + "client_secret_basic", + "client_secret_post", + }, + SubjectTypes: []string{"public"}, + IdTokenSigningAlgValues: []string{"RS256"}, + ClaimTypes: []string{"normal"}, + Claims: []string{ + "iss", + "sub", + "aud", + "exp", + "iat", + }, + } +} + func (p *IdentityProvider) ParseServerConfig(data []byte) error { // parse JSON into IdentityProvider fields var ep Endpoints