This commit is contained in:
Anders H 2018-07-24 19:44:34 +00:00 committed by GitHub
commit 0da3e407f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -452,7 +452,6 @@ func unpack(ctx *context.Context) *RequestVars {
// TODO cheap hack, unify with unpack // TODO cheap hack, unify with unpack
func unpackbatch(ctx *context.Context) *BatchVars { func unpackbatch(ctx *context.Context) *BatchVars {
r := ctx.Req r := ctx.Req
var bv BatchVars var bv BatchVars
@ -577,11 +576,33 @@ func parseToken(authorization string) (*models.User, *models.Repository, string,
user, password := cs[:i], cs[i+1:] user, password := cs[:i], cs[i+1:]
u, err := models.GetUserByName(user) u, err := models.GetUserByName(user)
if err != nil { if err != nil {
return nil, nil, "basic", err if models.IsErrUserNotExist(err) {
} isUsernameToken := len(password) == 0 || password == "x-oauth-basic"
if !u.ValidatePassword(password) { authToken := user
return nil, nil, "basic", fmt.Errorf("Basic auth failed")
if !isUsernameToken {
authToken = password
}
token, err := models.GetAccessTokenBySHA(authToken)
if err != nil {
return nil, nil, "basic", fmt.Errorf("Token not found")
}
u, err = models.GetUserByID(token.UID)
if err != nil {
return nil, nil, "basic", err
}
} else {
return nil, nil, "basic", err
}
} else {
if !u.ValidatePassword(password) {
return nil, nil, "basic", fmt.Errorf("Basic auth failed")
}
} }
return u, nil, "basic", nil return u, nil, "basic", nil
} }