Merge pull request #242 from ericchiang/duplicate_login
server: fix flow when user logs in through wrong connector
This commit is contained in:
commit
6c09576668
1 changed files with 14 additions and 18 deletions
|
@ -322,26 +322,22 @@ func (s *Server) Login(ident oidc.Identity, key string) (string, error) {
|
||||||
ConnectorID: ses.ConnectorID,
|
ConnectorID: ses.ConnectorID,
|
||||||
ID: ses.Identity.ID,
|
ID: ses.Identity.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
if err == user.ErrorNotFound {
|
if err == user.ErrorNotFound {
|
||||||
// If has authenticated via a connector, but no local identity there
|
// Does the user have an existing account with a different connector?
|
||||||
// are a couple of possibilities:
|
|
||||||
|
|
||||||
// * Maybe they are using the wrong connector:
|
|
||||||
if ses.Identity.Email != "" {
|
if ses.Identity.Email != "" {
|
||||||
if connID, err := getConnectorForUserByEmail(s.UserRepo,
|
connID, err := getConnectorForUserByEmail(s.UserRepo, ses.Identity.Email)
|
||||||
ses.Identity.Email); err == nil {
|
if err == nil {
|
||||||
|
// Ask user to sign in through existing account.
|
||||||
return newLoginURLFromSession(s.IssuerURL,
|
u := newLoginURLFromSession(s.IssuerURL, ses, false, []string{connID}, "wrong-connector")
|
||||||
ses, true, []string{connID},
|
return u.String(), nil
|
||||||
"wrong-connector").String(), nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// * User needs to register
|
// User doesn't have an existing account. Ask them to register.
|
||||||
return newLoginURLFromSession(s.IssuerURL,
|
u := newLoginURLFromSession(s.IssuerURL, ses, true, []string{ses.ConnectorID}, "register-maybe")
|
||||||
ses, true, []string{ses.ConnectorID}, "register-maybe").String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue