Fix test login url returns 404

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-12-24 12:13:11 +01:00
parent 80762de99b
commit 41a6df9aec
4 changed files with 6 additions and 18 deletions

View File

@@ -99,14 +99,6 @@ func (s *Service) Run(ctx context.Context) error {
} }
} }
func (s *Service) GetEntityID() string {
return fmt.Sprintf("%s/connect/saml/metadata", s.baseURL)
}
func (s *Service) GetAcsURL() string {
return fmt.Sprintf("%s/connect/saml/consume", s.baseURL)
}
func (s *Service) GenerateSpMetadata() ([]byte, error) { func (s *Service) GenerateSpMetadata() ([]byte, error) {
sp := s.baseServiceProvider() sp := s.baseServiceProvider()
return xml.MarshalIndent(sp.Metadata(), "", " ") return xml.MarshalIndent(sp.Metadata(), "", " ")

View File

@@ -21,6 +21,7 @@ import (
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
"github.com/vektah/gqlparser/v2/gqlerror" "github.com/vektah/gqlparser/v2/gqlerror"
"go.gearno.de/kit/log" "go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/baseurl"
"go.probo.inc/probo/pkg/iam" "go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/securecookie" "go.probo.inc/probo/pkg/securecookie"
"go.probo.inc/probo/pkg/server/api/connect/v1/schema" "go.probo.inc/probo/pkg/server/api/connect/v1/schema"
@@ -91,11 +92,12 @@ func IsViewerDirective(ctx context.Context, obj any, next graphql.Resolver) (any
return next(ctx) return next(ctx)
} }
func NewGraphQLHandler(svc *iam.Service, logger *log.Logger, cookieConfig securecookie.Config) http.Handler { func NewGraphQLHandler(svc *iam.Service, logger *log.Logger, baseURL *baseurl.BaseURL, cookieConfig securecookie.Config) http.Handler {
config := schema.Config{ config := schema.Config{
Resolvers: &Resolver{ Resolvers: &Resolver{
logger: logger, logger: logger,
iam: svc, iam: svc,
baseURL: baseURL,
cookieConfig: cookieConfig, cookieConfig: cookieConfig,
}, },
Directives: schema.DirectiveRoot{ Directives: schema.DirectiveRoot{

View File

@@ -30,6 +30,7 @@ type (
Resolver struct { Resolver struct {
logger *log.Logger logger *log.Logger
iam *iam.Service iam *iam.Service
baseURL *baseurl.BaseURL
cookieConfig securecookie.Config cookieConfig securecookie.Config
} }
) )
@@ -53,7 +54,7 @@ func NewMux(logger *log.Logger, svc *iam.Service, cookieConfig securecookie.Conf
r.Use(HTTPContextMiddleware) r.Use(HTTPContextMiddleware)
sessionMiddleware := NewSessionMiddleware(svc, cookieConfig) sessionMiddleware := NewSessionMiddleware(svc, cookieConfig)
graphqlHandler := NewGraphQLHandler(svc, logger, cookieConfig) graphqlHandler := NewGraphQLHandler(svc, logger, baseURL, cookieConfig)
samlHandler := NewSAMLHandler(svc, cookieConfig, baseURL) samlHandler := NewSAMLHandler(svc, cookieConfig, baseURL)
router := r.With(sessionMiddleware) router := r.With(sessionMiddleware)

View File

@@ -9,7 +9,6 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/99designs/gqlgen/graphql" "github.com/99designs/gqlgen/graphql"
@@ -1250,13 +1249,7 @@ func (r *queryResolver) CheckSSOAvailability(ctx context.Context, email string)
// TestLoginURL is the resolver for the testLoginUrl field. // TestLoginURL is the resolver for the testLoginUrl field.
func (r *sAMLConfigurationResolver) TestLoginURL(ctx context.Context, obj *types.SAMLConfiguration) (string, error) { func (r *sAMLConfigurationResolver) TestLoginURL(ctx context.Context, obj *types.SAMLConfiguration) (string, error) {
entityID := r.iam.SAMLService.GetEntityID() return r.baseURL.WithPath("/api/connect/v1/saml/2.0/" + obj.ID.String()).MustString(), nil
parts := strings.Split(entityID, "/connect/saml/metadata")
if len(parts) != 2 {
return "", fmt.Errorf("invalid entity ID format")
}
return fmt.Sprintf("%s/connect/saml/login/%s", parts[0], obj.ID), nil
} }
// TotalCount is the resolver for the totalCount field. // TotalCount is the resolver for the totalCount field.