frostfs-s3-gw/api/user-auth.go
Evgeniy Kulikov 2a93a216f8 Migrate to SDK 0.3.0 and fixes
- fix displaying list objects
- simplify `ListObjects`
- simplify `GetObjectHandler`
- simplify `HeadObjectHandler`
- add method for `GetBucketVersioningHandler`
- add method for `ListMultipartUploadsHandler`
- improvements for `HeadObjectHandler`, to display folders meta
- update dependencies
  - github.com/aws/aws-sdk-go v1.36.26
  - github.com/google/uuid v1.1.4
  - github.com/gorilla/mux v1.8.0
  - github.com/nspcc-dev/cdn-sdk v0.3.0
  - github.com/nspcc-dev/neofs-api-go v1.22.0
  - github.com/prometheus/client_golang v1.9.0
  - github.com/stretchr/testify v1.7.0
  - google.golang.org/grpc v1.35.0

Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
2021-01-14 20:39:48 +03:00

27 lines
671 B
Go

package api
import (
"net/http"
"github.com/gorilla/mux"
sdk "github.com/nspcc-dev/cdn-sdk"
"github.com/nspcc-dev/neofs-s3-gate/api/auth"
"go.uber.org/zap"
)
func AttachUserAuth(router *mux.Router, center auth.Center, log *zap.Logger) {
router.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token, err := center.Authenticate(r)
if err != nil {
log.Error("failed to pass authentication", zap.Error(err))
WriteErrorResponse(r.Context(), w, GetAPIError(ErrAccessDenied), r.URL)
return
}
h.ServeHTTP(w, r.WithContext(
sdk.SetBearerToken(r.Context(), token)))
})
})
}