use generic wopiContext.scope decoder
This commit is contained in:
@@ -12,12 +12,13 @@ import (
|
||||
"time"
|
||||
|
||||
appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
|
||||
link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1"
|
||||
auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1"
|
||||
providerv1beta1 "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
|
||||
rjwt "github.com/cs3org/reva/v2/pkg/token/manager/jwt"
|
||||
"github.com/cs3org/reva/v2/pkg/utils"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
|
||||
"github.com/owncloud/ocis/v2/services/collaboration/pkg/helpers"
|
||||
"github.com/rs/zerolog"
|
||||
@@ -38,21 +39,20 @@ type WopiContext struct {
|
||||
FileReference *providerv1beta1.Reference
|
||||
TemplateReference *providerv1beta1.Reference
|
||||
ViewMode appproviderv1beta1.ViewMode
|
||||
publicShare *link.PublicShare
|
||||
// scope contains decoded Scope map from the AccessToken
|
||||
scope map[string]*auth.Scope
|
||||
}
|
||||
|
||||
// GetPublicShare returns the public share from the WopiContext or nil if it doesn't exist
|
||||
func (w *WopiContext) GetPublicShare() *link.PublicShare {
|
||||
if w != nil {
|
||||
return w.publicShare
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EvaluatePublicShare unmashals the public share from the scope and
|
||||
func (w *WopiContext) EvaluatePublicShare() *link.PublicShare {
|
||||
if w != nil {
|
||||
return w.publicShare
|
||||
// GetScopeByKeyPrefix returns the scope from the AccessToken Scope map by key prefix
|
||||
func (w *WopiContext) GetScopeByKeyPrefix(keyPrefix string, m proto.Message) error {
|
||||
for k, v := range w.scope {
|
||||
if strings.HasPrefix(k, keyPrefix) && v.Resource.Decoder == "json" {
|
||||
err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, m)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't unmarshal public share from scope: %w", err)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -146,20 +146,8 @@ func WopiContextAuthMiddleware(cfg *config.Config, st microstore.Store, next htt
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range scope {
|
||||
if strings.HasPrefix(k, "publicshare:") && v.Resource.Decoder == "json" {
|
||||
share := &link.PublicShare{}
|
||||
err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, share)
|
||||
if err != nil {
|
||||
wopiLogger.Error().Err(err).Msg("can't unmarshal public share from scope")
|
||||
} else {
|
||||
claims.WopiContext.publicShare = share
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
claims.WopiContext.AccessToken = wopiContextAccessToken
|
||||
claims.WopiContext.scope = scope
|
||||
|
||||
ctx = context.WithValue(ctx, wopiContextKey, claims.WopiContext)
|
||||
// authentication for the CS3 api
|
||||
|
||||
Reference in New Issue
Block a user