mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-07 06:42:15 +00:00
fix: primary domain claim (#1082)
* fix: primary domain scope (overwrite by roles and rogue `:`) * disable wrong users * fix test * show requested org name * only show domain when selected
This commit is contained in:
@@ -188,16 +188,10 @@ func (l *Login) handleAutoRegister(w http.ResponseWriter, r *http.Request, authR
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: iam.GlobalOrgID},
|
||||
Roles: []string{orgProjectCreatorRole},
|
||||
}
|
||||
if authReq.GetScopeOrgPrimaryDomain() != "" {
|
||||
primaryDomain := authReq.GetScopeOrgPrimaryDomain()
|
||||
org, err := l.authRepo.GetOrgByPrimaryDomain(primaryDomain)
|
||||
if err != nil {
|
||||
l.renderExternalNotFoundOption(w, r, authReq, err)
|
||||
}
|
||||
if org.ID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = org.ID
|
||||
}
|
||||
|
||||
if authReq.RequestedOrgID != "" && authReq.RequestedOrgID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
|
||||
orgIamPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
|
||||
@@ -85,17 +85,9 @@ func (l *Login) handleExternalUserRegister(w http.ResponseWriter, r *http.Reques
|
||||
Roles: []string{orgProjectCreatorRole},
|
||||
}
|
||||
|
||||
if authReq.GetScopeOrgPrimaryDomain() != "" {
|
||||
primaryDomain := authReq.GetScopeOrgPrimaryDomain()
|
||||
org, err := l.authRepo.GetOrgByPrimaryDomain(primaryDomain)
|
||||
if err != nil {
|
||||
l.renderRegisterOption(w, r, authReq, err)
|
||||
return
|
||||
}
|
||||
if org.ID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = org.ID
|
||||
}
|
||||
if authReq.RequestedOrgID != "" && authReq.RequestedOrgID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = authReq.RequestedOrgID
|
||||
}
|
||||
orgIamPolicy, err := l.getOrgIamPolicy(r, resourceOwner)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"golang.org/x/text/language"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/caos/zitadel/internal/auth_request/model"
|
||||
caos_errs "github.com/caos/zitadel/internal/errors"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
@@ -71,17 +72,9 @@ func (l *Login) handleRegisterCheck(w http.ResponseWriter, r *http.Request) {
|
||||
ObjectRoot: models.ObjectRoot{AggregateID: iam.GlobalOrgID},
|
||||
Roles: []string{orgProjectCreatorRole},
|
||||
}
|
||||
if authRequest.GetScopeOrgPrimaryDomain() != "" {
|
||||
primaryDomain := authRequest.GetScopeOrgPrimaryDomain()
|
||||
org, err := l.authRepo.GetOrgByPrimaryDomain(primaryDomain)
|
||||
if err != nil {
|
||||
l.renderRegisterOption(w, r, authRequest, err)
|
||||
return
|
||||
}
|
||||
if org.ID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = org.ID
|
||||
}
|
||||
if authRequest.RequestedOrgID != "" && authRequest.RequestedOrgID != iam.GlobalOrgID {
|
||||
member = nil
|
||||
resourceOwner = authRequest.RequestedOrgID
|
||||
}
|
||||
user, err := l.authRepo.Register(setContext(r.Context(), resourceOwner), data.toUserModel(), member, resourceOwner)
|
||||
if err != nil {
|
||||
|
||||
@@ -267,6 +267,7 @@ func (l *Login) getBaseData(r *http.Request, authReq *model.AuthRequest, title s
|
||||
Theme: l.getTheme(r),
|
||||
ThemeMode: l.getThemeMode(r),
|
||||
OrgID: l.getOrgID(authReq),
|
||||
OrgName: l.getOrgName(authReq),
|
||||
AuthReqID: getRequestID(authReq, r),
|
||||
CSRF: csrf.TemplateField(r),
|
||||
Nonce: http_mw.GetNonce(r),
|
||||
@@ -312,20 +313,17 @@ func (l *Login) getOrgID(authReq *model.AuthRequest) string {
|
||||
if authReq == nil {
|
||||
return ""
|
||||
}
|
||||
if authReq.UserOrgID != "" {
|
||||
return authReq.UserOrgID
|
||||
if authReq.RequestedOrgID != "" {
|
||||
return authReq.RequestedOrgID
|
||||
}
|
||||
if authReq.Request == nil {
|
||||
return authReq.UserOrgID
|
||||
}
|
||||
|
||||
func (l *Login) getOrgName(authReq *model.AuthRequest) string {
|
||||
if authReq == nil {
|
||||
return ""
|
||||
}
|
||||
primaryDomain := authReq.GetScopeOrgPrimaryDomain()
|
||||
if primaryDomain != "" {
|
||||
org, _ := l.authRepo.GetOrgByPrimaryDomain(primaryDomain)
|
||||
if org != nil {
|
||||
return org.ID
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return authReq.RequestedOrgName
|
||||
}
|
||||
|
||||
func getRequestID(authReq *model.AuthRequest, r *http.Request) string {
|
||||
@@ -355,6 +353,7 @@ type baseData struct {
|
||||
Theme string
|
||||
ThemeMode string
|
||||
OrgID string
|
||||
OrgName string
|
||||
AuthReqID string
|
||||
CSRF template.HTML
|
||||
Nonce string
|
||||
|
||||
Reference in New Issue
Block a user