mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:57:32 +00:00
feat(queries): user IDP links (#2751)
This commit is contained in:
@@ -9,14 +9,18 @@ import (
|
||||
)
|
||||
|
||||
func (s *Server) ListMyLinkedIDPs(ctx context.Context, req *auth_pb.ListMyLinkedIDPsRequest) (*auth_pb.ListMyLinkedIDPsResponse, error) {
|
||||
idps, err := s.repo.SearchMyExternalIDPs(ctx, ListMyLinkedIDPsRequestToModel(req))
|
||||
q, err := ListMyLinkedIDPsRequestToQuery(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
idps, err := s.query.UserIDPLinks(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &auth_pb.ListMyLinkedIDPsResponse{
|
||||
Result: idp_grpc.IDPsToUserLinkPb(idps.Result),
|
||||
Result: idp_grpc.IDPUserLinksToPb(idps.Links),
|
||||
Details: object.ToListDetails(
|
||||
idps.TotalResult,
|
||||
idps.Count,
|
||||
idps.Sequence,
|
||||
idps.Timestamp,
|
||||
),
|
||||
|
@@ -3,19 +3,27 @@ package auth
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api/authz"
|
||||
"github.com/caos/zitadel/internal/api/grpc/object"
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/user/model"
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
auth_pb "github.com/caos/zitadel/pkg/grpc/auth"
|
||||
)
|
||||
|
||||
func ListMyLinkedIDPsRequestToModel(req *auth_pb.ListMyLinkedIDPsRequest) *model.ExternalIDPSearchRequest {
|
||||
func ListMyLinkedIDPsRequestToQuery(ctx context.Context, req *auth_pb.ListMyLinkedIDPsRequest) (*query.UserIDPLinksSearchQuery, error) {
|
||||
offset, limit, asc := object.ListQueryToModel(req.Query)
|
||||
return &model.ExternalIDPSearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
q, err := query.NewUserIDPLinksUserIDSearchQuery(authz.GetCtxData(ctx).UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &query.UserIDPLinksSearchQuery{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
},
|
||||
Queries: []query.SearchQuery{q},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func RemoveMyLinkedIDPRequestToDomain(ctx context.Context, req *auth_pb.RemoveMyLinkedIDPRequest) *domain.UserIDPLink {
|
||||
|
@@ -5,7 +5,6 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
iam_model "github.com/caos/zitadel/internal/iam/model"
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
user_model "github.com/caos/zitadel/internal/user/model"
|
||||
idp_pb "github.com/caos/zitadel/pkg/grpc/idp"
|
||||
)
|
||||
|
||||
@@ -61,31 +60,30 @@ func ExternalIDPViewToLoginPolicyLinkPb(link *iam_model.IDPProviderView) *idp_pb
|
||||
return &idp_pb.IDPLoginPolicyLink{
|
||||
IdpId: link.IDPConfigID,
|
||||
IdpName: link.Name,
|
||||
IdpType: IDPTypeToPb(link.IDPConfigType),
|
||||
IdpType: IDPTypeViewToPb(link.IDPConfigType),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPsToUserLinkPb(res []*user_model.ExternalIDPView) []*idp_pb.IDPUserLink {
|
||||
func IDPUserLinksToPb(res []*query.UserIDPLink) []*idp_pb.IDPUserLink {
|
||||
links := make([]*idp_pb.IDPUserLink, len(res))
|
||||
for i, link := range res {
|
||||
links[i] = ExternalIDPViewToUserLinkPb(link)
|
||||
links[i] = IDPUserLinkToPb(link)
|
||||
}
|
||||
return links
|
||||
}
|
||||
|
||||
func ExternalIDPViewToUserLinkPb(link *user_model.ExternalIDPView) *idp_pb.IDPUserLink {
|
||||
func IDPUserLinkToPb(link *query.UserIDPLink) *idp_pb.IDPUserLink {
|
||||
return &idp_pb.IDPUserLink{
|
||||
UserId: link.UserID,
|
||||
IdpId: link.IDPConfigID,
|
||||
IdpId: link.IDPID,
|
||||
IdpName: link.IDPName,
|
||||
ProvidedUserId: link.ExternalUserID,
|
||||
ProvidedUserName: link.UserDisplayName,
|
||||
//TODO: as soon as saml is implemented we need to switch here
|
||||
//IdpType: IDPTypeToPb(link.Type),
|
||||
ProvidedUserId: link.ProvidedUserID,
|
||||
ProvidedUserName: link.ProvidedUsername,
|
||||
IdpType: IDPTypeToPb(link.IDPType),
|
||||
}
|
||||
}
|
||||
|
||||
func IDPTypeToPb(idpType iam_model.IdpConfigType) idp_pb.IDPType {
|
||||
func IDPTypeViewToPb(idpType iam_model.IdpConfigType) idp_pb.IDPType {
|
||||
switch idpType {
|
||||
case iam_model.IDPConfigTypeOIDC:
|
||||
return idp_pb.IDPType_IDP_TYPE_OIDC
|
||||
@@ -98,6 +96,19 @@ func IDPTypeToPb(idpType iam_model.IdpConfigType) idp_pb.IDPType {
|
||||
}
|
||||
}
|
||||
|
||||
func IDPTypeToPb(idpType domain.IDPConfigType) idp_pb.IDPType {
|
||||
switch idpType {
|
||||
case domain.IDPConfigTypeOIDC:
|
||||
return idp_pb.IDPType_IDP_TYPE_OIDC
|
||||
case domain.IDPConfigTypeSAML:
|
||||
return idp_pb.IDPType_IDP_TYPE_UNSPECIFIED
|
||||
case domain.IDPConfigTypeJWT:
|
||||
return idp_pb.IDPType_IDP_TYPE_JWT
|
||||
default:
|
||||
return idp_pb.IDPType_IDP_TYPE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func IDPStateToPb(state domain.IDPConfigState) idp_pb.IDPState {
|
||||
switch state {
|
||||
case domain.IDPConfigStateActive:
|
||||
|
@@ -606,14 +606,18 @@ func (s *Server) RemoveMachineKey(ctx context.Context, req *mgmt_pb.RemoveMachin
|
||||
}
|
||||
|
||||
func (s *Server) ListHumanLinkedIDPs(ctx context.Context, req *mgmt_pb.ListHumanLinkedIDPsRequest) (*mgmt_pb.ListHumanLinkedIDPsResponse, error) {
|
||||
res, err := s.user.SearchExternalIDPs(ctx, ListHumanLinkedIDPsRequestToModel(req))
|
||||
queries, err := ListHumanLinkedIDPsRequestToQuery(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := s.query.UserIDPLinks(ctx, queries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &mgmt_pb.ListHumanLinkedIDPsResponse{
|
||||
Result: idp_grpc.IDPsToUserLinkPb(res.Result),
|
||||
Result: idp_grpc.IDPUserLinksToPb(res.Links),
|
||||
Details: obj_grpc.ToListDetails(
|
||||
res.TotalResult,
|
||||
res.Count,
|
||||
res.Sequence,
|
||||
res.Timestamp,
|
||||
),
|
||||
|
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/caos/zitadel/internal/domain"
|
||||
"github.com/caos/zitadel/internal/eventstore/v1/models"
|
||||
key_model "github.com/caos/zitadel/internal/key/model"
|
||||
"github.com/caos/zitadel/internal/query"
|
||||
user_model "github.com/caos/zitadel/internal/user/model"
|
||||
mgmt_pb "github.com/caos/zitadel/pkg/grpc/management"
|
||||
user_pb "github.com/caos/zitadel/pkg/grpc/user"
|
||||
@@ -234,14 +235,24 @@ func RemoveHumanLinkedIDPRequestToDomain(ctx context.Context, req *mgmt_pb.Remov
|
||||
}
|
||||
}
|
||||
|
||||
func ListHumanLinkedIDPsRequestToModel(req *mgmt_pb.ListHumanLinkedIDPsRequest) *user_model.ExternalIDPSearchRequest {
|
||||
func ListHumanLinkedIDPsRequestToQuery(ctx context.Context, req *mgmt_pb.ListHumanLinkedIDPsRequest) (*query.UserIDPLinksSearchQuery, error) {
|
||||
offset, limit, asc := object.ListQueryToModel(req.Query)
|
||||
return &user_model.ExternalIDPSearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
Queries: []*user_model.ExternalIDPSearchQuery{{Key: user_model.ExternalIDPSearchKeyUserID, Method: domain.SearchMethodEquals, Value: req.UserId}},
|
||||
userQuery, err := query.NewUserIDPLinksUserIDSearchQuery(req.UserId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resourceOwnerQuery, err := query.NewUserIDPLinksResourceOwnerSearchQuery(authz.GetCtxData(ctx).OrgID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &query.UserIDPLinksSearchQuery{
|
||||
SearchRequest: query.SearchRequest{
|
||||
Offset: offset,
|
||||
Limit: limit,
|
||||
Asc: asc,
|
||||
},
|
||||
Queries: []query.SearchQuery{userQuery, resourceOwnerQuery},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ListUserMembershipsRequestToModel(req *mgmt_pb.ListUserMembershipsRequest) (*user_model.UserMembershipSearchRequest, error) {
|
||||
|
Reference in New Issue
Block a user