This commit is contained in:
Leon Bösche
2026-01-08 13:07:07 +01:00
parent 87ee5f2ae3
commit 5cb99815a0
20 changed files with 1869 additions and 202 deletions

View File

@@ -14,13 +14,13 @@ import (
"golang.org/x/oauth2"
)
type Service struct {
type OIDCService struct {
provider *oidc.Provider
oauth2Config oauth2.Config
db *database.DB // Assume we have a DB wrapper
}
func NewService(cfg *config.Config, db *database.DB) (*Service, error) {
func NewOIDCService(cfg *config.Config, db *database.DB) (*OIDCService, error) {
ctx := context.Background()
provider, err := oidc.NewProvider(ctx, cfg.OIDCIssuerURL)
@@ -36,18 +36,18 @@ func NewService(cfg *config.Config, db *database.DB) (*Service, error) {
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
}
return &Service{
return &OIDCService{
provider: provider,
oauth2Config: oauth2Config,
db: db,
}, nil
}
func (s *Service) LoginURL(state string) string {
func (s *OIDCService) LoginURL(state string) string {
return s.oauth2Config.AuthCodeURL(state)
}
func (s *Service) HandleCallback(ctx context.Context, code, state string) (*database.User, *database.Session, error) {
func (s *OIDCService) HandleCallback(ctx context.Context, code, state string) (*database.User, *database.Session, error) {
oauth2Token, err := s.oauth2Config.Exchange(ctx, code)
if err != nil {
return nil, nil, fmt.Errorf("failed to exchange code: %w", err)