Documentation
¶
Index ¶
- Constants
- Variables
- func APIKeyHash(key string) string
- func ErrorResponse(w http.ResponseWriter, err error)
- func NewAuthn(cfg config.Auth, m metrics.Metrics, ust users.Store) (*authn, error)
- func UsernameFrom(ctx context.Context) *string
- type Authn
- type CreateAPIKeyRequest
- type PasswordValidationErr
- type Token
Constants ¶
View Source
const ( RefreshRealm = "me.dynatron.stillbox.refresh" AccessRealm = "me.dynatron.stillbox.access" APIKeyRealm = "me.dynatron.stillbox.apiKey" )
View Source
const ( CookieName = "stillboxJwt" MinimumPasswordEntropy = 50.0 )
View Source
const TokenFromHeaderKey tokenFromHeaderKey = "tokenFromHeader"
Variables ¶
View Source
var ( ErrLoginFailed = errors.New("Login failed") ErrInternal = errors.New("Internal server error") ErrBadRequest = errors.New("Bad request") )
View Source
var (
ErrBadRealm = errors.New("bad realm")
)
View Source
var (
ErrInvalidScopes = errors.New("invalid scope(s)")
)
View Source
var ErrPasswordValidation = errors.New("password validation error")
Functions ¶
func APIKeyHash ¶
func ErrorResponse ¶
func ErrorResponse(w http.ResponseWriter, err error)
ErrorResponse writes the error and appropriate HTTP response code.
func UsernameFrom ¶
UsernameFrom gets the username (just the subject from token) from ctx.
Types ¶
type Authn ¶
type Authn interface {
HUP(*config.Config)
// VerifyMiddleware will verify any JWT provided with the request.
VerifyMiddleware() func(http.Handler) http.Handler
// AuthorizedSubjectMiddleware requires a JWT be set.
AuthorizedSubjectMiddleware() func(http.Handler) http.Handler
// PublicSubjectMiddleware allows a Public subject to be set.
PublicSubjectMiddleware() func(http.Handler) http.Handler
// NewAccessToken generates a new access token.
NewAccessToken(username string) string
// MultipartAPIKeyMiddleware requires a multipart/form-data API key be set.
MultipartAPIKeyMiddleware(formKey string) func(http.Handler) http.Handler
// NewAPIKeyToken generates a JWT for use as an API key with the provided expiry and scopes.
NewAPIKeyToken(username string, expires *time.Time, keyID uuid.UUID, scopes []string) (string, error)
// LocalAdminMiddleware is used for local Unix domain socket connections..
LocalAdminMiddleware() func(http.Handler) http.Handler
// PrivateRoutes installs auth-specific private routes to the Router.
PrivateRoutes(r chi.Router)
// PublicRoutes installs auth-specific public routes to the Router.
PublicRoutes(r chi.Router)
// AllowInsecureCookie returns whether the request is for a host where we can allow insecure.
AllowInsecureCookie(*http.Request) bool
// ChangePassword changes a password. Privileged users can specify another username, and do not need to furnish an oldPassword; otherwise the user is grabbed from the context Subject.
ChangePassword(ctx context.Context, username, oldPassword *string, newPassword string) error
// CreateAPIKey creates and stores an API key according to rq.
CreateAPIKey(ctx context.Context, rq CreateAPIKeyRequest) (*users.APIKey, error)
}
Authn performs API key and user JWT authentication.
type CreateAPIKeyRequest ¶
type PasswordValidationErr ¶
type PasswordValidationErr struct {
// contains filtered or unexported fields
}
func (PasswordValidationErr) Unwrap ¶
func (p PasswordValidationErr) Unwrap() error
Click to show internal directories.
Click to hide internal directories.