Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

1.4 KB
Raw Blame
package middleware

import (
	"github.com/owncast/owncast/persistence/authrepository"
	"github.com/owncast/owncast/persistence/configrepository"
	"github.com/owncast/owncast/persistence/userrepository"
)

// Middleware bundles the dependencies needed by the HTTP middleware
// helpers in this package (admin basic-auth, external-API token auth,
// user-access-token auth, federation gating, etc.). Construct once in
// main() and inject into the components that wire HTTP routes.
type Middleware struct {
	configRepository configrepository.ConfigRepository
	authRepository   authrepository.AuthRepository
	userRepository   userrepository.UserRepository
	// adminSessions holds opaque admin session tokens. The admin UI mints
	// one after authenticating with Basic Auth, and embedded contexts
	// (plugin admin iframes) that cannot inject the Authorization header
	// themselves authenticate via this cookie instead.
	adminSessions *adminSessionStore
}

// Deps lists the services *Middleware consumes.
type Deps struct {
	ConfigRepository configrepository.ConfigRepository
	AuthRepository   authrepository.AuthRepository
	UserRepository   userrepository.UserRepository
}

// New constructs a *Middleware.
func New(deps Deps) *Middleware {
	return &Middleware{
		configRepository: deps.ConfigRepository,
		authRepository:   deps.AuthRepository,
		userRepository:   deps.UserRepository,
		adminSessions:    newAdminSessionStore(),
	}
}