feat: use short tokens as access tokens

The "real" access token will be stored using the short token as key.
This short token will be sent to the clients to be used as access token
for the WOPI server.

This is configurable, and requires a store in order to keep the tokens.
This commit is contained in:
Juan Pablo Villafáñez
2024-10-24 08:46:54 +02:00
parent 4dfba210e1
commit b8f8ca813e
14 changed files with 127 additions and 15 deletions
@@ -6,6 +6,7 @@ import (
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/config"
"github.com/owncloud/ocis/v2/services/collaboration/pkg/connector"
microstore "go-micro.dev/v4/store"
"go.opentelemetry.io/otel/trace"
)
@@ -19,6 +20,7 @@ type Options struct {
Context context.Context
Config *config.Config
TracerProvider trace.TracerProvider
Store microstore.Store
}
// newOptions initializes the available default options.
@@ -66,3 +68,10 @@ func TracerProvider(val trace.TracerProvider) Option {
o.TracerProvider = val
}
}
// Store provides a funtion to set the Store option
func Store(val microstore.Store) Option {
return func(o *Options) {
o.Store = val
}
}
@@ -119,7 +119,7 @@ func prepareRoutes(r *chi.Mux, options Options) {
r.Use(
func(h stdhttp.Handler) stdhttp.Handler {
// authentication and wopi context
return colabmiddleware.WopiContextAuthMiddleware(options.Config, h)
return colabmiddleware.WopiContextAuthMiddleware(options.Config, options.Store, h)
},
colabmiddleware.CollaborationTracingMiddleware,
)
@@ -186,7 +186,7 @@ func prepareRoutes(r *chi.Mux, options Options) {
r.Use(
func(h stdhttp.Handler) stdhttp.Handler {
// authentication and wopi context
return colabmiddleware.WopiContextAuthMiddleware(options.Config, h)
return colabmiddleware.WopiContextAuthMiddleware(options.Config, options.Store, h)
},
colabmiddleware.CollaborationTracingMiddleware,
)