fix: only show factors with state ready (#3081)

This commit is contained in:
Fabi 2022-01-21 09:27:57 +01:00 committed by GitHub
parent b363ddd707
commit 2592383a7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 0 deletions

View File

@ -22,6 +22,10 @@ func (s *Server) ListMyAuthFactors(ctx context.Context, _ *auth_pb.ListMyAuthFac
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = query.AppendStateQuery(domain.MFAStateReady)
if err != nil {
return nil, err
}
authMethods, err := s.query.SearchUserAuthMethods(ctx, query) authMethods, err := s.query.SearchUserAuthMethods(ctx, query)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -24,6 +24,10 @@ func (s *Server) ListMyPasswordless(ctx context.Context, _ *auth_pb.ListMyPasswo
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = query.AppendStateQuery(domain.MFAStateReady)
if err != nil {
return nil, err
}
authMethods, err := s.query.SearchUserAuthMethods(ctx, query) authMethods, err := s.query.SearchUserAuthMethods(ctx, query)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -522,6 +522,10 @@ func (s *Server) ListHumanAuthFactors(ctx context.Context, req *mgmt_pb.ListHuma
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = query.AppendStateQuery(domain.MFAStateReady)
if err != nil {
return nil, err
}
authMethods, err := s.query.SearchUserAuthMethods(ctx, query) authMethods, err := s.query.SearchUserAuthMethods(ctx, query)
if err != nil { if err != nil {
return nil, err return nil, err
@ -561,6 +565,10 @@ func (s *Server) ListHumanPasswordless(ctx context.Context, req *mgmt_pb.ListHum
if err != nil { if err != nil {
return nil, err return nil, err
} }
err = query.AppendStateQuery(domain.MFAStateReady)
if err != nil {
return nil, err
}
authMethods, err := s.query.SearchUserAuthMethods(ctx, query) authMethods, err := s.query.SearchUserAuthMethods(ctx, query)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -128,6 +128,10 @@ func NewUserAuthMethodTypeSearchQuery(value domain.UserAuthMethodType) (SearchQu
return NewNumberQuery(UserAuthMethodColumnMethodType, value, NumberEquals) return NewNumberQuery(UserAuthMethodColumnMethodType, value, NumberEquals)
} }
func NewUserAuthMethodStateSearchQuery(value domain.MFAState) (SearchQuery, error) {
return NewNumberQuery(UserAuthMethodColumnState, value, NumberEquals)
}
func NewUserAuthMethodTypesSearchQuery(values ...domain.UserAuthMethodType) (SearchQuery, error) { func NewUserAuthMethodTypesSearchQuery(values ...domain.UserAuthMethodType) (SearchQuery, error) {
list := make([]interface{}, len(values)) list := make([]interface{}, len(values))
for i, value := range values { for i, value := range values {
@ -163,6 +167,15 @@ func (r *UserAuthMethodSearchQueries) AppendTokenIDQuery(tokenID string) error {
return nil return nil
} }
func (r *UserAuthMethodSearchQueries) AppendStateQuery(state domain.MFAState) error {
query, err := NewUserAuthMethodStateSearchQuery(state)
if err != nil {
return err
}
r.Queries = append(r.Queries, query)
return nil
}
func (r *UserAuthMethodSearchQueries) AppendAuthMethodQuery(authMethod domain.UserAuthMethodType) error { func (r *UserAuthMethodSearchQueries) AppendAuthMethodQuery(authMethod domain.UserAuthMethodType) error {
query, err := NewUserAuthMethodTypeSearchQuery(authMethod) query, err := NewUserAuthMethodTypeSearchQuery(authMethod)
if err != nil { if err != nil {