api: GitHub compliance (#4549)

* Add undocumented endpoint for /repositories/:id

* GitHub API Compliance
This commit is contained in:
无闻
2017-06-05 15:34:11 -04:00
committed by GitHub
parent 3359b942b3
commit 51d7f1264b
4 changed files with 50 additions and 10 deletions

View File

@@ -15,8 +15,8 @@ import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/models/errors"
"github.com/gogits/gogs/pkg/tool"
"github.com/gogits/gogs/pkg/setting"
"github.com/gogits/gogs/pkg/tool"
)
func IsAPIPath(url string) bool {
@@ -24,17 +24,20 @@ func IsAPIPath(url string) bool {
}
// SignedInID returns the id of signed in user.
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
func SignedInID(c *macaron.Context, sess session.Store) int64 {
if !models.HasEngine {
return 0
}
// Check access token.
if IsAPIPath(ctx.Req.URL.Path) {
tokenSHA := ctx.Query("token")
if IsAPIPath(c.Req.URL.Path) {
tokenSHA := c.Query("token")
if len(tokenSHA) <= 0 {
tokenSHA = c.Query("access_token")
}
if len(tokenSHA) == 0 {
// Well, check with header again.
auHead := ctx.Req.Header.Get("Authorization")
auHead := c.Req.Header.Get("Authorization")
if len(auHead) > 0 {
auths := strings.Fields(auHead)
if len(auths) == 2 && auths[0] == "token" {