Documentation ¶
Index ¶
- Constants
- Variables
- func APIKeyMiddlewareGenerator() (mw func(http.Handler) http.Handler)
- func AuthUser(ctx context.Context, authMethods []entity.AuthMethod, userStore user.Store) (*entity.User, error)
- func AuthenticationMiddlewareGenerator(sessionStore sessions.SessionStore) (mw func(http.Handler) http.Handler)
- func ExpireCookie(ctx context.Context, sessID string) error
- func ExposeResponseWriterMiddleware(h http.Handler) http.Handler
- func GetAPIKey(ctx context.Context) (string, error)
- func GetSession(ctx context.Context) (*entity.Session, error)
- func InternalErr(err error) *connect.Error
- func InvalidArg(str string) *connect.Error
- func NotFound(str string) *connect.Error
- func PermissionDenied(str string) *connect.Error
- func PlaceInContext(ctx context.Context, session *entity.Session) context.Context
- func SetDefaultCookie(ctx context.Context, sessID string) error
- func StoreAPIKeyInContext(ctx context.Context, apikey string) context.Context
- func Unauthenticated(str string) *connect.Error
Constants ¶
const ApiKeyHeader = "X-Api-Key"
const RenewCookieTimer = time.Hour * 24 * 14
Variables ¶
var ApiKeyFirst = []entity.AuthMethod{entity.AuthMethodAPIKey, entity.AuthMethodCookie}
var CookieFirst = []entity.AuthMethod{entity.AuthMethodCookie, entity.AuthMethodAPIKey}
var CookieOnly = []entity.AuthMethod{entity.AuthMethodCookie}
var ErrAuthFailed = errors.New("auth-methods-failed")
Functions ¶
func APIKeyMiddlewareGenerator ¶
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 ExposeResponseWriterMiddleware ¶
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 ¶
GetAPIKey works with APIKeyMiddlewareGenerator to return an API key in the passed-in context.
func InternalErr ¶
InternalErr sends a 500, it is a good way of transparently passing through an error.
func InvalidArg ¶
func PermissionDenied ¶
func PlaceInContext ¶
func StoreAPIKeyInContext ¶
func Unauthenticated ¶
Types ¶
This section is empty.