1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00
This commit is contained in:
Unknwon
2014-11-07 14:46:13 -05:00
parent a01b4baca2
commit abc57b6e43
6 changed files with 53 additions and 35 deletions

View File

@@ -7,8 +7,6 @@ package repo
import (
"bytes"
"compress/gzip"
"encoding/base64"
"errors"
"fmt"
"io"
"io/ioutil"
@@ -16,6 +14,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
@@ -29,27 +28,6 @@ import (
"github.com/gogits/gogs/modules/setting"
)
func basicEncode(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}
func basicDecode(encoded string) (user string, name string, err error) {
var s []byte
s, err = base64.StdEncoding.DecodeString(encoded)
if err != nil {
return user, name, err
}
a := strings.Split(string(s), ":")
if len(a) == 2 {
user, name = a[0], a[1]
} else {
err = errors.New("decode failed")
}
return user, name, err
}
func authRequired(ctx *middleware.Context) {
ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
ctx.Data["ErrorMsg"] = "no basic auth and digit auth"
@@ -112,11 +90,12 @@ func Http(ctx *middleware.Context) {
auths := strings.Fields(baHead)
// currently check basic auth
// TODO: support digit auth
// FIXME: middlewares/context.go did basic auth check already
if len(auths) != 2 || auths[0] != "Basic" {
ctx.Handle(401, "no basic auth and digit auth", nil)
return
}
authUsername, passwd, err = basicDecode(auths[1])
authUsername, passwd, err = base.BasicAuthDecode(auths[1])
if err != nil {
ctx.Handle(401, "no basic auth and digit auth", nil)
return