mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-19 19:17:01 -07:00
Added serve command to start an identity provider server
This commit is contained in:
parent
7529d2b7dd
commit
059fb37aaf
1 changed files with 31 additions and 0 deletions
31
cmd/serve.go
Normal file
31
cmd/serve.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue