Add setting bearer token in container list method
This commit is contained in:
parent
324bbdb934
commit
1aa22329fa
2 changed files with 5 additions and 6 deletions
|
@ -6,13 +6,10 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/minio/minio/auth"
|
"github.com/minio/minio/auth"
|
||||||
|
s3http "github.com/minio/minio/http"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContextKey string
|
|
||||||
|
|
||||||
const BearerTokenContextKey ContextKey = "bearer-token"
|
|
||||||
|
|
||||||
func attachNewUserAuth(router *mux.Router, center *auth.Center, log *zap.Logger) {
|
func attachNewUserAuth(router *mux.Router, center *auth.Center, log *zap.Logger) {
|
||||||
uamw := func(h http.Handler) http.Handler {
|
uamw := func(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -21,7 +18,7 @@ func attachNewUserAuth(router *mux.Router, center *auth.Center, log *zap.Logger)
|
||||||
log.Error("failed to pass authentication", zap.Error(err))
|
log.Error("failed to pass authentication", zap.Error(err))
|
||||||
// TODO: Handle any auth error by rejecting request.
|
// TODO: Handle any auth error by rejecting request.
|
||||||
}
|
}
|
||||||
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), BearerTokenContextKey, bearerToken)))
|
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), s3http.BearerTokenContextKey, bearerToken)))
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
|
||||||
|
s3http "github.com/minio/minio/http"
|
||||||
"github.com/nspcc-dev/neofs-api-go/container"
|
"github.com/nspcc-dev/neofs-api-go/container"
|
||||||
"github.com/nspcc-dev/neofs-api-go/refs"
|
"github.com/nspcc-dev/neofs-api-go/refs"
|
||||||
"github.com/nspcc-dev/neofs-api-go/service"
|
"github.com/nspcc-dev/neofs-api-go/service"
|
||||||
|
@ -16,7 +17,8 @@ func (n *neofsObject) containerList(ctx context.Context) ([]refs.CID, error) {
|
||||||
req.OwnerID = n.owner
|
req.OwnerID = n.owner
|
||||||
req.SetTTL(service.SingleForwardingTTL)
|
req.SetTTL(service.SingleForwardingTTL)
|
||||||
req.SetVersion(APIVersion)
|
req.SetVersion(APIVersion)
|
||||||
req.SetBearer(nil)
|
bearerToken := ctx.Value(s3http.BearerTokenContextKey).(*service.BearerTokenMsg)
|
||||||
|
req.SetBearer(bearerToken)
|
||||||
|
|
||||||
err := service.SignRequestData(n.key, req)
|
err := service.SignRequestData(n.key, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue