mirror of
https://github.com/zitadel/oidc.git
synced 2026-01-19 09:45:38 -06:00
# Conflicts: # README.md # example/client/app/app.go # example/server/exampleop/op.go # example/server/main.go # pkg/client/client.go # pkg/client/rp/relying_party.go # pkg/client/rp/relying_party_test.go # pkg/client/tokenexchange/tokenexchange.go # pkg/crypto/key_test.go # pkg/oidc/token.go # pkg/oidc/verifier.go # pkg/op/auth_request.go # pkg/op/device.go # pkg/op/server_http_routes_test.go # pkg/op/token.go # pkg/op/token_refresh.go
67 lines
1.7 KiB
Go
67 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/zitadel/oidc/v4/example/server/config"
|
|
"github.com/zitadel/oidc/v4/example/server/exampleop"
|
|
"github.com/zitadel/oidc/v4/example/server/storage"
|
|
)
|
|
|
|
func getUserStore(cfg *config.Config) (storage.UserStore, error) {
|
|
if cfg.UsersFile == "" {
|
|
return storage.NewUserStore(fmt.Sprintf("http://localhost:%s/", cfg.Port)), nil
|
|
}
|
|
return storage.StoreFromFile(cfg.UsersFile)
|
|
}
|
|
|
|
func main() {
|
|
cfg := config.FromEnvVars(&config.Config{Port: "9998"})
|
|
logger := slog.New(
|
|
slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
|
|
AddSource: true,
|
|
Level: slog.LevelDebug,
|
|
}),
|
|
)
|
|
|
|
//which gives us the issuer: http://localhost:9998/
|
|
issuer := fmt.Sprintf("http://localhost:%s/", cfg.Port)
|
|
|
|
storage.RegisterClients(
|
|
storage.NativeClient("native", cfg.RedirectURI...),
|
|
storage.WebClient("web", "secret", cfg.RedirectURI...),
|
|
storage.WebClient("api", "secret", cfg.RedirectURI...),
|
|
)
|
|
|
|
// the OpenIDProvider interface needs a Storage interface handling various checks and state manipulations
|
|
// this might be the layer for accessing your database
|
|
// in this example it will be handled in-memory
|
|
store, err := getUserStore(cfg)
|
|
if err != nil {
|
|
logger.Error("cannot create UserStore", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
stor := storage.NewStorage(store)
|
|
router := exampleop.SetupServer(
|
|
issuer,
|
|
stor,
|
|
logger,
|
|
false,
|
|
//op.WithCrypto(newMyCrypto(sha256.Sum256([]byte("test")), logger)),
|
|
)
|
|
|
|
server := &http.Server{
|
|
Addr: ":" + cfg.Port,
|
|
Handler: router,
|
|
}
|
|
logger.Info("server listening, press ctrl+c to stop", "addr", issuer)
|
|
if server.ListenAndServe() != http.ErrServerClosed {
|
|
logger.Error("server terminated", "error", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|