Documentation
ยถ
Index ยถ
- Constants
- Variables
- func AuthCookieGet(r *http.Request) string
- func AuthCookieRemove(w http.ResponseWriter, r *http.Request, opts ...types.CookieOption)
- func AuthCookieSet(w http.ResponseWriter, r *http.Request, token string, ...)
- func AuthTokenRetrieve(r *http.Request, useCookies bool) string
- func GetImpersonatorUserID(r *http.Request) string
- func IsImpersonating(r *http.Request) bool
- func NewAuthKnightAuth(config types.ConfigAuthKnight) (types.AuthAuthKnightInterface, error)
- func NewAuthKnightMethod(a types.AuthAuthKnightInterface) types.Method
- func NewMagicLinkMethod(page http.HandlerFunc, sendDeps api_magic_link_send.Dependencies, ...) types.Method
- func NewMagicLinkMethodFromAuth(a types.AuthSharedInterface, page http.HandlerFunc, ...) types.Method
- func NewOTPMethod(a types.AuthSharedInterface) types.Method
- func NewOTPMethodWithPage(a types.AuthSharedInterface, page http.HandlerFunc) types.Method
- func NewOtpAuth(config types.ConfigOtp) (types.AuthOtpInterface, error)
- func NewPasswordMethod(a types.AuthSharedInterface, page http.HandlerFunc) types.Method
- func NewUsernameAndPasswordAuth(config types.ConfigUsernameAndPassword) (types.AuthPasswordInterface, error)
- type AuthError
- func NewAuthenticationError(err error) *AuthError
- func NewCodeGenerationError(err error) *AuthError
- func NewEmailSendError(err error) *AuthError
- func NewInternalError(err error) *AuthError
- func NewLogoutError(err error) *AuthError
- func NewPasswordResetError(err error) *AuthError
- func NewRegistrationError(err error) *AuthError
- func NewSerializationError(err error) *AuthError
- func NewTokenStoreError(err error) *AuthError
- type AuthenticatedUserID
- type CookieConfig
- type LoginUsernameAndPasswordResponse
- type MultiMethodAuth
- type RegisterUsernameAndPasswordResponse
Constants ยถ
const ( // Path constants re-exported from types for backward compatibility PathApiLogin = authtypes.PathApiLogin PathApiLoginCodeVerify = authtypes.PathApiLoginCodeVerify PathApiLogout = authtypes.PathApiLogout PathApiRegister = authtypes.PathApiRegister PathApiRegisterCodeVerify = authtypes.PathApiRegisterCodeVerify PathApiRestorePassword = authtypes.PathApiRestorePassword PathApiResetPassword = authtypes.PathApiResetPassword PathApiImpersonateStart = authtypes.PathApiImpersonateStart PathApiImpersonateStop = authtypes.PathApiImpersonateStop PathApiAuthKnightCallback = authtypes.PathApiAuthKnightCallback AuthKnightBaseURL = authtypes.AuthKnightBaseURL PathLogin = authtypes.PathLogin PathLoginCodeVerify = authtypes.PathLoginCodeVerify PathLogout = authtypes.PathLogout PathRegister = authtypes.PathRegister PathRegisterCodeVerify = authtypes.PathRegisterCodeVerify PathPasswordRestore = authtypes.PathPasswordRestore PathPasswordReset = authtypes.PathPasswordReset EndpointLogin = authtypes.EndpointLogin EndpointLoginCodeVerify = authtypes.EndpointLoginCodeVerify EndpointRegister = authtypes.EndpointRegister EndpointRegisterCodeVerify = authtypes.EndpointRegisterCodeVerify EndpointPasswordReset = authtypes.EndpointPasswordReset EndpointPasswordRestore = authtypes.EndpointPasswordRestore EndpointImpersonateStart = authtypes.EndpointImpersonateStart EndpointImpersonateStop = authtypes.EndpointImpersonateStop EndpointAuthKnightCallback = authtypes.EndpointAuthKnightCallback // LoginCodeLength specified the length of the login code LoginCodeLength int = 8 // LoginCodeGamma specifies the characters to be used for building the login code LoginCodeGamma string = "BCDFGHJKLMNPQRSTVXYZ" DefaultVerificationCodeExpiration = 1 * time.Hour DefaultPasswordResetExpiration = 1 * time.Hour DefaultAuthTokenExpiration = 2 * time.Hour DefaultMaxLoginAttempts = 5 DefaultLockoutDuration = 15 * time.Minute )
const ( ErrCodeEmailSendFailed = "EMAIL_SEND_FAILED" ErrCodeTokenStoreFailed = "TOKEN_STORE_FAILED" ErrCodeValidationFailed = "VALIDATION_FAILED" ErrCodeAuthenticationFailed = "AUTHENTICATION_FAILED" ErrCodeRegistrationFailed = "REGISTRATION_FAILED" ErrCodeLogoutFailed = "LOGOUT_FAILED" ErrCodeInternalError = "INTERNAL_ERROR" ErrCodeCodeGenerationFailed = "CODE_GENERATION_FAILED" ErrCodeSerializationFailed = "SERIALIZATION_FAILED" ErrCodePasswordResetFailed = "PASSWORD_RESET_FAILED" )
Error codes for consistent error handling
const DefaultSessionTTL = 2 * time.Hour
DefaultSessionTTL is the lifetime of sessions minted by the store-derived FuncSessionCreate (remember-me issues longer-lived sessions via its own hook).
Variables ยถ
var CookieName = "authtoken"
Functions ยถ
func AuthCookieGet ยถ
AuthCookieGet returns the authentication cookie value, or an empty string if missing.
func AuthCookieRemove ยถ
func AuthCookieRemove(w http.ResponseWriter, r *http.Request, opts ...types.CookieOption)
AuthCookieRemove removes the authentication cookie. Options are applied on top of defaults.
func AuthCookieSet ยถ
func AuthCookieSet(w http.ResponseWriter, r *http.Request, token string, opts ...types.CookieOption)
AuthCookieSet sets the authentication cookie. Options are applied on top of defaults.
func AuthTokenRetrieve ยถ
AuthTokenRetrieve retrieves the auth token from the request.
func GetImpersonatorUserID ยถ added in v0.33.0
func IsImpersonating ยถ added in v0.33.0
func NewAuthKnightAuth ยถ added in v0.35.0
func NewAuthKnightAuth(config types.ConfigAuthKnight) (types.AuthAuthKnightInterface, error)
NewAuthKnightAuth creates a new AuthKnight-based authentication instance. It validates the provided ConfigAuthKnight and returns an error if required fields are missing.
func NewAuthKnightMethod ยถ added in v0.37.0
func NewAuthKnightMethod(a types.AuthAuthKnightInterface) types.Method
NewAuthKnightMethod adapts AuthKnight login to types.Method.
func NewMagicLinkMethod ยถ added in v0.37.0
func NewMagicLinkMethod( page http.HandlerFunc, sendDeps api_magic_link_send.Dependencies, callbackDeps api_magic_link_callback.Dependencies, ) types.Method
NewMagicLinkMethod adapts the magic-link login to types.Method. The page handler is supplied by the caller (a simple email form posting to the send ajax is enough); sendDeps/callbackDeps are the 007 dependency sets. page must not be nil โ there is no package default page for this method.
func NewMagicLinkMethodFromAuth ยถ added in v0.38.0
func NewMagicLinkMethodFromAuth( a types.AuthSharedInterface, page http.HandlerFunc, linkCallback func(token string) string, opts ...func(*api_magic_link_send.Dependencies, *api_magic_link_callback.Dependencies), ) types.Method
NewMagicLinkMethodFromAuth builds the magic-link method from an AuthSharedInterface โ the public counterpart to NewMagicLinkMethod, which takes internal dep types that external apps cannot construct. linkCallback builds the callback URL for a token (e.g. "/auth/magiclink-callback?token=" + token). page may be nil โ the package's generic magic-link page is used then.
func NewOTPMethod ยถ added in v0.37.0
func NewOTPMethod(a types.AuthSharedInterface) types.Method
NewOTPMethod adapts the otp email-code login to types.Method.
func NewOTPMethodWithPage ยถ added in v0.38.0
func NewOTPMethodWithPage(a types.AuthSharedInterface, page http.HandlerFunc) types.Method
NewOTPMethodWithPage is NewOTPMethod with a caller-supplied login page โ for apps that want their own template over the package's generic one.
func NewOtpAuth ยถ added in v0.49.0
func NewOtpAuth(config types.ConfigOtp) (types.AuthOtpInterface, error)
func NewPasswordMethod ยถ added in v0.37.0
func NewPasswordMethod(a types.AuthSharedInterface, page http.HandlerFunc) types.Method
NewPasswordMethod adapts the username/password login to types.Method. page is the login page handler; recovery routes mount only when this method is in the list (RouteProvider).
func NewUsernameAndPasswordAuth ยถ
func NewUsernameAndPasswordAuth(config types.ConfigUsernameAndPassword) (types.AuthPasswordInterface, error)
Types ยถ
type AuthError ยถ added in v0.29.0
type AuthError struct {
Code string
Message string // User-facing message
InternalErr error // For logging only, never exposed to users
}
AuthError represents a structured authentication error with a code, user-facing message, and internal error details for logging.
func NewAuthenticationError ยถ added in v0.29.0
NewAuthenticationError creates an AuthError for authentication failures.
func NewCodeGenerationError ยถ added in v0.29.0
NewCodeGenerationError creates an AuthError for code generation failures.
func NewEmailSendError ยถ added in v0.29.0
NewEmailSendError creates an AuthError for email send failures.
func NewInternalError ยถ added in v0.29.0
NewInternalError creates an AuthError for generic internal errors.
func NewLogoutError ยถ added in v0.29.0
NewLogoutError creates an AuthError for logout failures.
func NewPasswordResetError ยถ added in v0.29.0
NewPasswordResetError creates an AuthError for password reset failures.
func NewRegistrationError ยถ added in v0.29.0
NewRegistrationError creates an AuthError for registration failures.
func NewSerializationError ยถ added in v0.29.0
NewSerializationError creates an AuthError for data serialization failures.
func NewTokenStoreError ยถ added in v0.29.0
NewTokenStoreError creates an AuthError for token store failures.
type AuthenticatedUserID ยถ
type AuthenticatedUserID struct{}
type CookieConfig ยถ added in v0.29.0
type CookieConfig = authtypes.CookieConfig
type LoginUsernameAndPasswordResponse ยถ
type LoginUsernameAndPasswordResponse struct {
ErrorMessage string
SuccessMessage string
Token string
}
func LoginWithUsernameAndPassword ยถ added in v0.30.0
func LoginWithUsernameAndPassword( ctx context.Context, a types.AuthPasswordInterface, email string, password string, options types.UserAuthOptions, ) LoginUsernameAndPasswordResponse
LoginWithUsernameAndPassword is a standalone helper that performs the username/password login flow using the provided AuthPasswordInterface implementation.
type MultiMethodAuth ยถ added in v0.37.0
type MultiMethodAuth struct {
// contains filtered or unexported fields
}
MultiMethodAuth composes N login methods behind a single mux: the first (primary) method mounts at <endpoint>/login, secondary methods at <endpoint>/login-<name>, method callbacks mount once each regardless of position, and method-provided extra routes (e.g. password recovery) mount only when the providing method is in the list.
Custom methods implement types.Method โ no library change needed.
func NewMultiMethodAuth ยถ added in v0.37.0
func NewMultiMethodAuth(endpoint string, methods []types.Method) (*MultiMethodAuth, error)
NewMultiMethodAuth builds the composed mux. Returns an error for an empty method list or duplicate method names (no silent shadowing).
func (*MultiMethodAuth) Handler ยถ added in v0.37.0
func (m *MultiMethodAuth) Handler() http.Handler
Handler returns the composed http.Handler (the underlying ServeMux).
func (*MultiMethodAuth) LoginAlternativesHTML ยถ added in v0.37.0
func (m *MultiMethodAuth) LoginAlternativesHTML(currentMethod string) string
LoginAlternativesHTML renders the "OR โ use another method" fragment for the given current method name. Pages (built-in or app-supplied) can embed it so users can switch between mounted methods.
func (*MultiMethodAuth) Methods ยถ added in v0.37.0
func (m *MultiMethodAuth) Methods() []types.Method
Methods returns the configured method list (primary first).
func (*MultiMethodAuth) Router ยถ added in v0.37.0
func (m *MultiMethodAuth) Router() *http.ServeMux
Router returns the composed *http.ServeMux.
type RegisterUsernameAndPasswordResponse ยถ
type RegisterUsernameAndPasswordResponse struct {
ErrorMessage string
SuccessMessage string
Token string
}
func RegisterWithUsernameAndPassword ยถ added in v0.30.0
func RegisterWithUsernameAndPassword( ctx context.Context, a types.AuthPasswordInterface, email string, password string, firstName string, lastName string, options types.UserAuthOptions, ) RegisterUsernameAndPasswordResponse
RegisterWithUsernameAndPassword is a standalone helper that performs the username/password registration flow using the provided AuthPasswordInterface implementation.
Source Files
ยถ
Directories
ยถ
| Path | Synopsis |
|---|---|
|
examples
|
|
|
authknight
command
|
|
|
background
command
Background example: full-page photo backdrop behind the auth panel.
|
Background example: full-page photo backdrop behind the auth panel. |
|
customui
command
Custom UI example: demonstrates branding, custom CSS, and site layout embedding.
|
Custom UI example: demonstrates branding, custom CSS, and site layout embedding. |
|
impersonation
command
Impersonation example: demonstrates administrator "login as" feature.
|
Impersonation example: demonstrates administrator "login as" feature. |
|
magiclink
command
Magic link example: standalone magic link authentication flow.
|
Magic link example: standalone magic link authentication flow. |
|
multimethod
command
Multi-method example: mounts username/password, email OTP, and magic-link login on a single mux via auth.NewMultiMethodAuth.
|
Multi-method example: mounts username/password, email OTP, and magic-link login on a single mux via auth.NewMultiMethodAuth. |
|
otp
command
|
|
|
usernamepassword
command
|
|
|
internal
|
|
|
api/api_magic_link_callback
Package api_magic_link_callback provides the single-use GET callback that redeems a magic login link.
|
Package api_magic_link_callback provides the single-use GET callback that redeems a magic login link. |
|
api/api_magic_link_send
Package api_magic_link_send provides the JSON endpoint that sends a single-use magic login link to an email address.
|
Package api_magic_link_send provides the JSON endpoint that sends a single-use magic login link to an email address. |
|
rules
Package rules contains the reusable verification rules shared by the code-verify flows (login and register).
|
Package rules contains the reusable verification rules shared by the code-verify flows (login and register). |
|
ui/page_magic_link
Package page_magic_link renders the package's generic magic-link login page โ an email form posting to the same path that serves it (the method's send ajax is mounted on the same route).
|
Package page_magic_link renders the package's generic magic-link login page โ an email form posting to the same path that serves it (the method's send ajax is mounted on the same route). |
|
Remember-me exchange middleware.
|
Remember-me exchange middleware. |
|
This is a tiny JSON database
|
This is a tiny JSON database |