From 51d7f1264bc39a75b4fb016bee7d0f87f8485f3f Mon Sep 17 00:00:00 2001 From: 无闻 Date: Mon, 5 Jun 2017 15:34:11 -0400 Subject: api: GitHub compliance (#4549) * Add undocumented endpoint for /repositories/:id * GitHub API Compliance --- pkg/auth/auth.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'pkg/auth/auth.go') diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go index a52ef958..ba9ccce1 100644 --- a/pkg/auth/auth.go +++ b/pkg/auth/auth.go @@ -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" { -- cgit v1.2.3