mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-13 11:34:26 +00:00
b6b5b1b782
* feat: jwt idp * feat: command side * feat: add tests * fill idp views with jwt idps and return apis * add jwtEndpoint to jwt idp * begin jwt request handling * merge * handle jwt idp * cleanup * fixes * autoregister * get token from specific header name * error handling * fix texts * handle renderExternalNotFoundOption Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
155 lines
4.9 KiB
Go
155 lines
4.9 KiB
Go
package management
|
|
|
|
import (
|
|
idp_grpc "github.com/caos/zitadel/internal/api/grpc/idp"
|
|
"github.com/caos/zitadel/internal/api/grpc/object"
|
|
"github.com/caos/zitadel/internal/domain"
|
|
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
|
iam_model "github.com/caos/zitadel/internal/iam/model"
|
|
user_model "github.com/caos/zitadel/internal/user/model"
|
|
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
|
|
)
|
|
|
|
func addOIDCIDPRequestToDomain(req *mgmt_pb.AddOrgOIDCIDPRequest) *domain.IDPConfig {
|
|
return &domain.IDPConfig{
|
|
Name: req.Name,
|
|
OIDCConfig: addOIDCIDPRequestToDomainOIDCIDPConfig(req),
|
|
StylingType: idp_grpc.IDPStylingTypeToDomain(req.StylingType),
|
|
Type: domain.IDPConfigTypeOIDC,
|
|
AutoRegister: req.AutoRegister,
|
|
}
|
|
}
|
|
|
|
func addOIDCIDPRequestToDomainOIDCIDPConfig(req *mgmt_pb.AddOrgOIDCIDPRequest) *domain.OIDCIDPConfig {
|
|
return &domain.OIDCIDPConfig{
|
|
ClientID: req.ClientId,
|
|
ClientSecretString: req.ClientSecret,
|
|
Issuer: req.Issuer,
|
|
Scopes: req.Scopes,
|
|
IDPDisplayNameMapping: idp_grpc.MappingFieldToDomain(req.DisplayNameMapping),
|
|
UsernameMapping: idp_grpc.MappingFieldToDomain(req.UsernameMapping),
|
|
}
|
|
}
|
|
|
|
func addJWTIDPRequestToDomain(req *mgmt_pb.AddOrgJWTIDPRequest) *domain.IDPConfig {
|
|
return &domain.IDPConfig{
|
|
Name: req.Name,
|
|
JWTConfig: addJWTIDPRequestToDomainJWTIDPConfig(req),
|
|
StylingType: idp_grpc.IDPStylingTypeToDomain(req.StylingType),
|
|
Type: domain.IDPConfigTypeJWT,
|
|
AutoRegister: req.AutoRegister,
|
|
}
|
|
}
|
|
|
|
func addJWTIDPRequestToDomainJWTIDPConfig(req *mgmt_pb.AddOrgJWTIDPRequest) *domain.JWTIDPConfig {
|
|
return &domain.JWTIDPConfig{
|
|
JWTEndpoint: req.JwtEndpoint,
|
|
Issuer: req.Issuer,
|
|
KeysEndpoint: req.KeysEndpoint,
|
|
HeaderName: req.HeaderName,
|
|
}
|
|
}
|
|
|
|
func updateIDPToDomain(req *mgmt_pb.UpdateOrgIDPRequest) *domain.IDPConfig {
|
|
return &domain.IDPConfig{
|
|
IDPConfigID: req.IdpId,
|
|
Name: req.Name,
|
|
StylingType: idp_grpc.IDPStylingTypeToDomain(req.StylingType),
|
|
AutoRegister: req.AutoRegister,
|
|
}
|
|
}
|
|
|
|
func updateOIDCConfigToDomain(req *mgmt_pb.UpdateOrgIDPOIDCConfigRequest) *domain.OIDCIDPConfig {
|
|
return &domain.OIDCIDPConfig{
|
|
IDPConfigID: req.IdpId,
|
|
ClientID: req.ClientId,
|
|
ClientSecretString: req.ClientSecret,
|
|
Issuer: req.Issuer,
|
|
Scopes: req.Scopes,
|
|
IDPDisplayNameMapping: idp_grpc.MappingFieldToDomain(req.DisplayNameMapping),
|
|
UsernameMapping: idp_grpc.MappingFieldToDomain(req.UsernameMapping),
|
|
}
|
|
}
|
|
|
|
func updateJWTConfigToDomain(req *mgmt_pb.UpdateOrgIDPJWTConfigRequest) *domain.JWTIDPConfig {
|
|
return &domain.JWTIDPConfig{
|
|
IDPConfigID: req.IdpId,
|
|
JWTEndpoint: req.JwtEndpoint,
|
|
Issuer: req.Issuer,
|
|
KeysEndpoint: req.KeysEndpoint,
|
|
HeaderName: req.HeaderName,
|
|
}
|
|
}
|
|
|
|
func listIDPsToModel(req *mgmt_pb.ListOrgIDPsRequest) *iam_model.IDPConfigSearchRequest {
|
|
offset, limit, asc := object.ListQueryToModel(req.Query)
|
|
return &iam_model.IDPConfigSearchRequest{
|
|
Offset: offset,
|
|
Limit: limit,
|
|
Asc: asc,
|
|
SortingColumn: idp_grpc.FieldNameToModel(req.SortingColumn),
|
|
Queries: idpQueriesToModel(req.Queries),
|
|
}
|
|
}
|
|
|
|
func idpQueriesToModel(queries []*mgmt_pb.IDPQuery) []*iam_model.IDPConfigSearchQuery {
|
|
q := make([]*iam_model.IDPConfigSearchQuery, len(queries))
|
|
for i, query := range queries {
|
|
q[i] = idpQueryToModel(query)
|
|
}
|
|
|
|
return q
|
|
}
|
|
|
|
func idpQueryToModel(query *mgmt_pb.IDPQuery) *iam_model.IDPConfigSearchQuery {
|
|
switch q := query.Query.(type) {
|
|
case *mgmt_pb.IDPQuery_IdpNameQuery:
|
|
return idp_grpc.IDPNameQueryToModel(q.IdpNameQuery)
|
|
case *mgmt_pb.IDPQuery_IdpIdQuery:
|
|
return idp_grpc.IDPIDQueryToModel(q.IdpIdQuery)
|
|
case *mgmt_pb.IDPQuery_OwnerTypeQuery:
|
|
return idp_grpc.IDPOwnerTypeQueryToModel(q.OwnerTypeQuery)
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func idpProviderViewsToDomain(idps []*iam_model.IDPProviderView) []*domain.IDPProvider {
|
|
idpProvider := make([]*domain.IDPProvider, len(idps))
|
|
for i, idp := range idps {
|
|
idpProvider[i] = &domain.IDPProvider{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: idp.AggregateID,
|
|
},
|
|
IDPConfigID: idp.IDPConfigID,
|
|
Type: idpConfigTypeToDomain(idp.IDPProviderType),
|
|
}
|
|
}
|
|
return idpProvider
|
|
}
|
|
|
|
func idpConfigTypeToDomain(idpType iam_model.IDPProviderType) domain.IdentityProviderType {
|
|
switch idpType {
|
|
case iam_model.IDPProviderTypeOrg:
|
|
return domain.IdentityProviderTypeOrg
|
|
default:
|
|
return domain.IdentityProviderTypeSystem
|
|
}
|
|
}
|
|
|
|
func externalIDPViewsToDomain(idps []*user_model.ExternalIDPView) []*domain.ExternalIDP {
|
|
externalIDPs := make([]*domain.ExternalIDP, len(idps))
|
|
for i, idp := range idps {
|
|
externalIDPs[i] = &domain.ExternalIDP{
|
|
ObjectRoot: models.ObjectRoot{
|
|
AggregateID: idp.UserID,
|
|
ResourceOwner: idp.ResourceOwner,
|
|
},
|
|
IDPConfigID: idp.IDPConfigID,
|
|
ExternalUserID: idp.ExternalUserID,
|
|
DisplayName: idp.UserDisplayName,
|
|
}
|
|
}
|
|
return externalIDPs
|
|
}
|