Made it possible to override certain example IDP endpoints

This commit is contained in:
David J. Allen 2024-04-29 18:45:30 -06:00
parent f10a771db6
commit 73e4e50d44
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
4 changed files with 57 additions and 18 deletions

View file

@ -2,6 +2,7 @@ package cmd
import (
opaal "davidallendj/opaal/internal"
"davidallendj/opaal/internal/oidc"
"errors"
"fmt"
"net/http"
@ -9,23 +10,31 @@ import (
"github.com/spf13/cobra"
)
var exampleCmd = &cobra.Command{
var (
endpoints oidc.Endpoints
)
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start an simple identity provider server",
Short: "Start an simple, bare minimal identity provider server",
Long: "The built-in identity provider is not (nor meant to be) a complete OIDC implementation and behaves like an external IdP",
Run: func(cmd *cobra.Command, args []string) {
s := opaal.NewServerWithConfig(&config)
// FIXME: change how the server address is set with `NewServerWithConfig`
s.Server.Addr = fmt.Sprintf("%s:%d", s.Issuer.Host, s.Issuer.Port)
err := s.StartIdentityProvider()
err := s.StartIdentityProvider(endpoints)
if errors.Is(err, http.ErrServerClosed) {
fmt.Printf("Identity provider server closed.\n")
} else if err != nil {
fmt.Errorf("failed to start server: %v", err)
fmt.Printf("failed to start server: %v", err)
}
},
}
func init() {
rootCmd.AddCommand(exampleCmd)
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")
rootCmd.AddCommand(serveCmd)
}