feat(login): default to user selection, take login_hint into account (#350)

* feat(login): default to user selection instead of login, take login_hint into account

* fix: proper error message when user (and other objects) not found (#337)

* fix: proper error message when user not found by loginname

* add more not found and fix some typos

* feat: usergrant (#348)

* fix: add needed permissions

* feat: search project/projectgrant user grants

* fix: no zitadel permissions

* fix: queries length

* feat: add get my password policy (#346)

* feat: add get my password policy

* fix: failed merges

* chore(deps): bump contrib.go.opencensus.io/exporter/stackdriver (#343)

Bumps [contrib.go.opencensus.io/exporter/stackdriver](https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver) from 0.13.1 to 0.13.2.
- [Release notes](https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/releases)
- [Commits](https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/compare/v0.13.1...v0.13.2)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: remove phone (#349)

* feat: remove phone number

* feat: remove phone number tests

* feat: remove phone number tests

* fix: regenerate protos

* fix(console): distinct user grant searches and creates, project grant member edit, import cleanup (#342)

* project grant member edit

* project grant member dialog, import cleanup

* readd project roles

* user login-methods cleanup

* fix sw config, user grant context

* delete user grants, context for creation, search

* contributor box shadow

* password to detail view

* user detail notification

* lint

Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Peintner <max@caos.ch>
This commit is contained in:
Livio Amstutz 2020-07-07 08:14:44 +02:00 committed by GitHub
parent 9935784461
commit 65b17a83fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 8 deletions

View File

@ -72,6 +72,10 @@ func (repo *AuthRequestRepo) CreateAuthRequest(ctx context.Context, request *mod
return nil, err return nil, err
} }
request.Audience = ids request.Audience = ids
if request.LoginHint != "" {
err = repo.checkLoginName(request, request.LoginHint)
logging.LogWithFields("EVENT-aG311", "login name", request.LoginHint, "id", request.ID, "applicationID", request.ApplicationID).Debug("login hint invalid")
}
err = repo.AuthRequests.SaveAuthRequest(ctx, request) err = repo.AuthRequests.SaveAuthRequest(ctx, request)
if err != nil { if err != nil {
return nil, err return nil, err
@ -118,11 +122,10 @@ func (repo *AuthRequestRepo) CheckLoginName(ctx context.Context, id, loginName s
if err != nil { if err != nil {
return err return err
} }
user, err := repo.View.UserByLoginName(loginName) err = repo.checkLoginName(request, loginName)
if err != nil { if err != nil {
return err return err
} }
request.SetUserInfo(user.ID, loginName, user.ResourceOwner)
return repo.AuthRequests.UpdateAuthRequest(ctx, request) return repo.AuthRequests.UpdateAuthRequest(ctx, request)
} }
@ -174,6 +177,15 @@ func (repo *AuthRequestRepo) getAuthRequest(ctx context.Context, id string, chec
return request, nil return request, nil
} }
func (repo *AuthRequestRepo) checkLoginName(request *model.AuthRequest, loginName string) error {
user, err := repo.View.UserByLoginName(loginName)
if err != nil {
return err
}
request.SetUserInfo(user.ID, loginName, user.ResourceOwner)
return nil
}
func (repo *AuthRequestRepo) nextSteps(ctx context.Context, request *model.AuthRequest, checkLoggedIn bool) ([]model.NextStep, error) { func (repo *AuthRequestRepo) nextSteps(ctx context.Context, request *model.AuthRequest, checkLoggedIn bool) ([]model.NextStep, error) {
if request == nil { if request == nil {
return nil, errors.ThrowInvalidArgument(nil, "EVENT-ds27a", "Errors.Internal") return nil, errors.ThrowInvalidArgument(nil, "EVENT-ds27a", "Errors.Internal")
@ -184,12 +196,14 @@ func (repo *AuthRequestRepo) nextSteps(ctx context.Context, request *model.AuthR
} }
if request.UserID == "" { if request.UserID == "" {
steps = append(steps, &model.LoginStep{}) steps = append(steps, &model.LoginStep{})
if request.Prompt == model.PromptSelectAccount { if request.Prompt == model.PromptSelectAccount || request.Prompt == model.PromptUnspecified {
users, err := repo.usersForUserSelection(request) users, err := repo.usersForUserSelection(request)
if err != nil { if err != nil {
return nil, err return nil, err
} }
steps = append(steps, &model.SelectUserStep{Users: users}) if len(users) > 0 || request.Prompt == model.PromptSelectAccount {
steps = append(steps, &model.SelectUserStep{Users: users})
}
} }
return steps, nil return steps, nil
} }

View File

@ -28,7 +28,7 @@ func (m *mockViewNoUserSession) UserSessionByIDs(string, string) (*user_view_mod
} }
func (m *mockViewNoUserSession) UserSessionsByAgentID(string) ([]*user_view_model.UserSessionView, error) { func (m *mockViewNoUserSession) UserSessionsByAgentID(string) ([]*user_view_model.UserSessionView, error) {
return nil, errors.ThrowInternal(nil, "id", "internal error") return nil, nil
} }
type mockViewErrUserSession struct{} type mockViewErrUserSession struct{}
@ -173,8 +173,10 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) {
nil, nil,
}, },
{ {
"user not set, login step", "user not set no active session, login step",
fields{}, fields{
userSessionViewProvider: &mockViewNoUserSession{},
},
args{&model.AuthRequest{}, false}, args{&model.AuthRequest{}, false},
[]model.NextStep{&model.LoginStep{}}, []model.NextStep{&model.LoginStep{}},
nil, nil,
@ -182,7 +184,7 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) {
{ {
"user not set, prompt select account and internal error, internal error", "user not set, prompt select account and internal error, internal error",
fields{ fields{
userSessionViewProvider: &mockViewNoUserSession{}, userSessionViewProvider: &mockViewErrUserSession{},
}, },
args{&model.AuthRequest{Prompt: model.PromptSelectAccount}, false}, args{&model.AuthRequest{Prompt: model.PromptSelectAccount}, false},
nil, nil,
@ -222,6 +224,22 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) {
}}, }},
nil, nil,
}, },
{
"user not set, prompt select account, no active session, login and select account steps",
fields{
userSessionViewProvider: &mockViewUserSession{
Users: nil,
},
userEventProvider: &mockEventUser{},
},
args{&model.AuthRequest{Prompt: model.PromptSelectAccount}, false},
[]model.NextStep{
&model.LoginStep{},
&model.SelectUserStep{
Users: []model.UserSelection{},
}},
nil,
},
{ {
"user not found, not found error", "user not found, not found error",
fields{ fields{
@ -248,6 +266,22 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) {
nil, nil,
errors.IsPreconditionFailed, errors.IsPreconditionFailed,
}, },
{
"user locked, precondition failed error",
fields{
userViewProvider: &mockViewUser{},
userEventProvider: &mockEventUser{
&es_models.Event{
AggregateType: user_es_model.UserAggregate,
Type: user_es_model.UserLocked,
},
},
orgViewProvider: &mockViewOrg{State: org_model.OrgStateActive},
},
args{&model.AuthRequest{UserID: "UserID"}, false},
nil,
errors.IsPreconditionFailed,
},
{ {
"org error, internal error", "org error, internal error",
fields{ fields{