@@ -6,13 +6,15 @@ import (
66 "encoding/base64"
77 "encoding/binary"
88 "encoding/hex"
9+ "fmt"
910 "io"
1011 "net/url"
1112 "path"
1213 "strings"
1314 "time"
1415
1516 appproviderv1beta1 "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
17+ auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1"
1618 gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
1719 userv1beta1 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
1820 rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
@@ -23,6 +25,7 @@ import (
2325 "github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
2426 "github.com/cs3org/reva/v2/pkg/storagespace"
2527 "github.com/cs3org/reva/v2/pkg/utils"
28+ "github.com/golang/protobuf/proto"
2629 "github.com/google/uuid"
2730 "github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
2831 "github.com/owncloud/ocis/v2/services/collaboration/pkg/connector/fileinfo"
@@ -1230,7 +1233,7 @@ func (f *FileConnector) CheckFileInfo(ctx context.Context) (*ConnectorResponse,
12301233 } else {
12311234 if scopes , ok := ctxpkg .ContextGetScopes (ctx ); ok {
12321235 publicShare := & link.PublicShare {}
1233- if err := helpers . GetScopeByKeyPrefix (scopes , "publicshare:" , publicShare ); err == nil {
1236+ if err := f . getScopeByKeyPrefix (scopes , "publicshare:" , publicShare ); err == nil {
12341237 parentFolderURL .Path = path .Join (ocisURL .Path , "s" , publicShare .GetToken ())
12351238 } else {
12361239 logger .Error ().Err (err ).Msg ("CheckFileInfo: error getting public share scope" )
@@ -1483,3 +1486,17 @@ func (f *FileConnector) adjustWopiReference(ctx context.Context, wopiContext *mi
14831486
14841487 return newStatRes .GetInfo (), nil
14851488}
1489+
1490+ // getScopeByKeyPrefix returns the scope from the AccessToken Scope map by key prefix
1491+ func (f * FileConnector ) getScopeByKeyPrefix (scopes map [string ]* auth.Scope , keyPrefix string , m proto.Message ) error {
1492+ for k , v := range scopes {
1493+ if strings .HasPrefix (k , keyPrefix ) && v .Resource .Decoder == "json" {
1494+ err := utils .UnmarshalJSONToProtoV1 (v .Resource .Value , m )
1495+ if err != nil {
1496+ return fmt .Errorf ("can't unmarshal public share from scope: %w" , err )
1497+ }
1498+ return nil
1499+ }
1500+ }
1501+ return fmt .Errorf ("scope %s not found" , keyPrefix )
1502+ }
0 commit comments