apiserver

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ApiKeyHeader = "X-Api-Key"
View Source
const RenewCookieTimer = time.Hour * 24 * 14

Variables

View Source
var ErrAuthFailed = errors.New("auth-methods-failed")

Functions

func APIKeyMiddlewareGenerator

func APIKeyMiddlewareGenerator() (mw func(http.Handler) http.Handler)

APIKeyMiddlewareGenerator creates a middleware to fetch an API key from a header and store it in a context key.

func AuthUser

func AuthUser(ctx context.Context, authMethods []entity.AuthMethod, userStore user.Store) (*entity.User, error)

AuthUser uses the passed-in auth methods to authenticate the user. It uses the first one that passes. If the method fails outright though, it returns an error; i.e. if the API key is wrong or the cookie has expired, it won't try the other method.

func AuthenticationMiddlewareGenerator

func AuthenticationMiddlewareGenerator(sessionStore sessions.SessionStore) (mw func(http.Handler) http.Handler)

AuthenticationMiddlewareGenerator generates auth middleware that looks up a session ID, and attaches a Session to the request context (at `sesskey`)

func ExpireCookie

func ExpireCookie(ctx context.Context, sessID string) error

func ExposeResponseWriterMiddleware

func ExposeResponseWriterMiddleware(h http.Handler) http.Handler

ExposeResponseWriterMiddleware configures an http.Handler (like any Connect server) to place the responseWriter in its context. This should enable setting cookies with the setCookie function.

func GetAPIKey

func GetAPIKey(ctx context.Context) (string, error)

GetAPIKey works with APIKeyMiddlewareGenerator to return an API key in the passed-in context.

func GetSession

func GetSession(ctx context.Context) (*entity.Session, error)

func InternalErr

func InternalErr(err error) *connect.Error

InternalErr sends a 500, it is a good way of transparently passing through an error.

func InvalidArg

func InvalidArg(str string) *connect.Error

func NotFound

func NotFound(str string) *connect.Error

func PermissionDenied

func PermissionDenied(str string) *connect.Error

func PlaceInContext

func PlaceInContext(ctx context.Context, session *entity.Session) context.Context

func SetDefaultCookie

func SetDefaultCookie(ctx context.Context, sessID string) error

func StoreAPIKeyInContext

func StoreAPIKeyInContext(ctx context.Context, apikey string) context.Context

func Unauthenticated

func Unauthenticated(str string) *connect.Error

Types

This section is empty.

Jump to

Keyboard shortcuts

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