mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-30 17:13:08 +08:00
allow login without specifying user's domain
This commit is contained in:
@@ -91,10 +91,14 @@ func authUserByIdentity(ctx context.Context, ident mcclient.SAuthenticationIdent
|
||||
return nil, errors.Wrap(err, "Query user")
|
||||
}
|
||||
idmap, err := models.IdmappingManager.FetchEntity(usr.Id, api.IdMappingEntityUser)
|
||||
if err != nil {
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return nil, errors.Wrap(err, "IdmappingManager.FetchEntity")
|
||||
}
|
||||
idpId = idmap.IdpId
|
||||
if idmap == nil { // sql
|
||||
idpId = api.DEFAULT_IDP_ID
|
||||
} else {
|
||||
idpId = idmap.IdpId
|
||||
}
|
||||
}
|
||||
} else {
|
||||
usrExt, err := models.UserManager.FetchUserExtended(ident.Password.User.Id, ident.Password.User.Name,
|
||||
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"net/http"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/identity"
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
@@ -86,7 +88,11 @@ func authenticateTokensV3(ctx context.Context, w http.ResponseWriter, r *http.Re
|
||||
input.Auth.Context = FetchAuthContext(input.Auth.Context, r)
|
||||
token, err := AuthenticateV3(ctx, input)
|
||||
if err != nil {
|
||||
httperrors.UnauthorizedError(w, "unauthorized %s", err)
|
||||
if errors.Cause(err) == sqlchemy.ErrDuplicateEntry {
|
||||
httperrors.ConflictError(w, "duplicate username")
|
||||
} else {
|
||||
httperrors.UnauthorizedError(w, "unauthorized %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if token == nil {
|
||||
|
||||
@@ -135,9 +135,10 @@ func (this *Client) _authV3(domainName, uname, passwd, projectId, projectName, t
|
||||
input.Auth.Identity.Password.User.Password = passwd
|
||||
if len(domainName) > 0 {
|
||||
input.Auth.Identity.Password.User.Domain.Name = domainName
|
||||
} else {
|
||||
input.Auth.Identity.Password.User.Domain.Name = api.DEFAULT_DOMAIN_ID
|
||||
}
|
||||
// else {
|
||||
// input.Auth.Identity.Password.User.Domain.Name = api.DEFAULT_DOMAIN_ID
|
||||
//}
|
||||
} else if len(token) > 0 {
|
||||
input.Auth.Identity.Methods = []string{api.AUTH_METHOD_TOKEN}
|
||||
input.Auth.Identity.Token.Id = token
|
||||
|
||||
Reference in New Issue
Block a user