Merge pull request #2831 from owncloud/public-link-signature-auth

enable signature auth in public share auth middleware
This commit is contained in:
David Christofas
2021-12-10 09:33:41 +01:00
committed by GitHub
2 changed files with 22 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
Enhancement: Support signature auth in the public share auth middleware
Enabled public share requests to be authenticated using the public share signature.
https://github.com/owncloud/ocis/pull/2831

View File

@@ -2,6 +2,7 @@ package middleware
import (
"net/http"
"strings"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
)
@@ -32,12 +33,23 @@ func PublicShareAuth(opts ...Option) func(next http.Handler) http.Handler {
return
}
// We can ignore the username since it is always set to "public" in public shares.
_, password, ok := r.BasicAuth()
var sharePassword string
if signature := r.URL.Query().Get("signature"); signature != "" {
expiration := r.URL.Query().Get("expiration")
if expiration == "" {
logger.Warn().Str("signature", signature).Msg("cannot do signature auth without the expiration")
next.ServeHTTP(w, r)
return
}
sharePassword = strings.Join([]string{"signature", signature, expiration}, "|")
} else {
// We can ignore the username since it is always set to "public" in public shares.
_, password, ok := r.BasicAuth()
sharePassword := basicAuthPasswordPrefix
if ok {
sharePassword += password
sharePassword = basicAuthPasswordPrefix
if ok {
sharePassword += password
}
}
authResp, err := options.RevaGatewayClient.Authenticate(r.Context(), &gateway.AuthenticateRequest{