Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow token as authorization for accessing attachments #7909

Merged
merged 3 commits into from
Aug 24, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ func IsAPIPath(url string) bool {
return strings.HasPrefix(url, "/api/")
}

// IsAttachmentDownload check if request is a file download (GET) with URL to an attachment
func IsAttachmentDownload(ctx *macaron.Context) bool {
return strings.HasPrefix(ctx.Req.URL.Path, "/attachments/") && ctx.Req.Method == "GET"
}

// SignedInID returns the id of signed in user.
func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
if !models.HasEngine {
return 0
}

// Check access token.
if IsAPIPath(ctx.Req.URL.Path) {
if IsAPIPath(ctx.Req.URL.Path) || IsAttachmentDownload(ctx) {
tokenSHA := ctx.Query("token")
if len(tokenSHA) == 0 {
tokenSHA = ctx.Query("access_token")
Expand Down