middleware

package
v1.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2025 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessLog

func AccessLog(logger log.Logger) func(http.Handler) http.Handler

AccessLog is a middleware to log http requests at info level logging.

func CollaborationTracingMiddleware

func CollaborationTracingMiddleware(next http.Handler) http.Handler

CollaborationTracingMiddleware adds a new middleware in order to include more attributes in the traced span.

In order not to mess with the expected responses, this middleware won't do anything if there is no available WOPI context set in the request (there is nothing to report). This means that the WopiContextAuthMiddleware should be set before this middleware.

func DecryptAES

func DecryptAES(key []byte, securemess string) (string, error)

DecryptAES decrypts the provided string using the provided key. The provided string must have been encrypted with AES CFB. This method will decrypt the result from the EncryptAES method

func EncryptAES

func EncryptAES(key []byte, plainText string) (string, error)

EncryptAES encrypts the provided plainText using the provided key. AES CFB will be used as cryptographic method. Use DecryptAES to decrypt the resulting string

func GenerateWopiToken

func GenerateWopiToken(wopiContext WopiContext, cfg *config.Config, st microstore.Store) (string, int64, error)

The access token inside the wopiContext is expected to be decrypted. In order to generate the access token for WOPI, the reva token inside the wopiContext will be encrypted

func ProofKeysMiddleware

func ProofKeysMiddleware(cfg *config.Config, next http.Handler) http.Handler

ProofKeysMiddleware will verify the proof keys of the requests. This is a middleware that could be disabled / not set.

Requests will fail with a 500 HTTP status if the verification fails. As said, this can be disabled (via configuration) if you want to skip the verification. The middleware requires hitting the "/hosting/discovery" endpoint of the WOPI app in order to get the keys. The keys will be cached in memory for 12 hours (or the configured value) before hitting the endpoint again to request new / updated keys.

func WopiContextAuthMiddleware

func WopiContextAuthMiddleware(cfg *config.Config, st microstore.Store, next http.Handler) http.Handler

WopiContextAuthMiddleware will prepare an HTTP handler to be used as middleware. The handler will create a WopiContext by parsing the access_token (which must be provided as part of the URL query). The access_token is required.

This middleware will add the following to the request's context: * The access token as metadata for outgoing requests (for the authentication against the CS3 API, the "x-access-token" header). * The created WopiContext for the request * A contextual zerologger containing information about the request and the WopiContext

func WopiContextToCtx

func WopiContextToCtx(ctx context.Context, wopiContext WopiContext) context.Context

Set a WopiContext in the context. A new context will be returned with the add WopiContext inside. Note that the old one won't have the WopiContext set.

This method is used for testing. The WopiContextAuthMiddleware should be used instead in order to provide a valid WopiContext

Types

type Claims

type Claims struct {
	WopiContext WopiContext `json:"WopiContext"`
	jwt.RegisteredClaims
}

Claims contains the jwt registered claims plus the used WOPI context

type WopiContext

type WopiContext struct {
	AccessToken       string
	ViewOnlyToken     string
	FileReference     *providerv1beta1.Reference
	TemplateReference *providerv1beta1.Reference
	ViewMode          appproviderv1beta1.ViewMode
}

WopiContext wraps all the information we need for WOPI

func WopiContextFromCtx

func WopiContextFromCtx(ctx context.Context) (WopiContext, error)

Extract a WopiContext from the context if possible. An error will be returned if there is no WopiContext

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL