godash/handlers/auth.handlers.go

37 lines
1 KiB
Go
Raw Normal View History

2024-03-18 21:54:35 +01:00
package handlers
import (
2024-04-12 16:19:11 +02:00
"context"
"log/slog"
"os"
2024-04-04 09:25:59 +02:00
"gitlab.unjx.de/flohoss/godash/internal/env"
2024-04-12 16:19:11 +02:00
"github.com/zitadel/oidc/v3/pkg/oidc"
"github.com/zitadel/zitadel-go/v3/pkg/authentication"
openid "github.com/zitadel/zitadel-go/v3/pkg/authentication/oidc"
"github.com/zitadel/zitadel-go/v3/pkg/zitadel"
)
2024-04-04 09:25:59 +02:00
2024-04-12 16:19:11 +02:00
func NewAuthHandler(env *env.Config) *AuthHandler {
ctx := context.Background()
authN, err := authentication.New(ctx, zitadel.New(env.OIDCIssuerUrl), env.OIDCClientSecret,
openid.DefaultAuthentication(env.OIDCClientId, env.OIDCRedirectUri, env.OIDCClientSecret),
2024-04-04 09:25:59 +02:00
)
if err != nil {
2024-04-12 16:19:11 +02:00
slog.Error("zitadel sdk could not initialize", "error", err)
os.Exit(1)
}
2024-04-12 16:19:11 +02:00
mw := authentication.Middleware(authN)
2024-04-12 16:19:11 +02:00
return &AuthHandler{
authenticator: authN,
middleware: mw,
2024-04-04 09:25:59 +02:00
}
}
2024-04-12 16:19:11 +02:00
type AuthHandler struct {
authenticator *authentication.Authenticator[*openid.UserInfoContext[*oidc.IDTokenClaims, *oidc.UserInfo]]
middleware *authentication.Interceptor[*openid.UserInfoContext[*oidc.IDTokenClaims, *oidc.UserInfo]]
2024-03-18 21:54:35 +01:00
}