Added serve command to start an identity provider server

This commit is contained in:
David J. Allen 2024-04-17 17:26:03 -06:00
parent 7529d2b7dd
commit 059fb37aaf
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC

31
cmd/serve.go Normal file
View file

@ -0,0 +1,31 @@
package cmd
import (
opaal "davidallendj/opaal/internal"
"errors"
"fmt"
"net/http"
"github.com/spf13/cobra"
)
var exampleCmd = &cobra.Command{
Use: "serve",
Short: "Start an simple 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()
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)
}
},
}
func init() {
rootCmd.AddCommand(exampleCmd)
}