Skip to content

Commit

Permalink
enable signature auth in public share auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
David Christofas committed Dec 9, 2021
1 parent a2681cb commit a85644c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/public-link-signature-auth.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 17 additions & 5 deletions proxy/pkg/middleware/public_share_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package middleware

import (
"net/http"
"strings"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit a85644c

Please sign in to comment.