Implement redirect path for SAML SSO
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -19,6 +19,8 @@ type (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
Nil = GID{}
|
Nil = GID{}
|
||||||
|
|
||||||
|
EncodedGIDSize = base64.RawURLEncoding.EncodedLen(GIDSize)
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParseGID parses a string representation of a GID
|
// ParseGID parses a string representation of a GID
|
||||||
|
|||||||
@@ -153,11 +153,9 @@ func (s *Service) InitiateLogin(
|
|||||||
return fmt.Errorf("cannot insert SAML request: %w", err)
|
return fmt.Errorf("cannot insert SAML request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
relayState := url.Values{}
|
relayState := config.ID.String() + redirectPath
|
||||||
relayState.Add("config-id", config.ID.String())
|
|
||||||
relayState.Add("redirect-path", redirectPath)
|
|
||||||
|
|
||||||
redirect, err = req.Redirect(url.QueryEscape(relayState.Encode()), sp)
|
redirect, err = req.Redirect(relayState, sp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot generate redirect URL: %w", err)
|
return fmt.Errorf("cannot generate redirect URL: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"go.gearno.de/kit/httpserver"
|
"go.gearno.de/kit/httpserver"
|
||||||
@@ -59,13 +58,12 @@ func (h *SAMLHandler) ConsumeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
samlResponse := r.FormValue("SAMLResponse")
|
samlResponse := r.FormValue("SAMLResponse")
|
||||||
relayState := r.FormValue("RelayState")
|
relayState := r.FormValue("RelayState")
|
||||||
|
|
||||||
values, err := url.ParseQuery(relayState)
|
if len(relayState) < gid.EncodedGIDSize {
|
||||||
if err != nil {
|
|
||||||
httpserver.RenderError(w, http.StatusBadRequest, errors.New("invalid relay state"))
|
httpserver.RenderError(w, http.StatusBadRequest, errors.New("invalid relay state"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configIDStr := values.Get("config-id")
|
configIDStr := relayState[:gid.EncodedGIDSize+1]
|
||||||
if configIDStr == "" {
|
if configIDStr == "" {
|
||||||
httpserver.RenderError(w, http.StatusBadRequest, errors.New("missing config ID"))
|
httpserver.RenderError(w, http.StatusBadRequest, errors.New("missing config ID"))
|
||||||
return
|
return
|
||||||
@@ -77,7 +75,7 @@ func (h *SAMLHandler) ConsumeHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectPath := values.Get("redirect-path")
|
redirectPath := relayState[gid.EncodedGIDSize+1:]
|
||||||
|
|
||||||
user, membership, err := h.iam.SAMLService.HandleAssertion(ctx, samlResponse, configID)
|
user, membership, err := h.iam.SAMLService.HandleAssertion(ctx, samlResponse, configID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user