Documentation
¶
Index ¶
- Constants
- Variables
- func CodeVerifierFromCookie(c fiber.Ctx, cfg Config) (string, error)
- func ContextWithProvider(ctx fiber.Ctx, provider string) fiber.Ctx
- func DecryptCookie(value, key string) (string, error)
- func EncryptCookie(value, key string) (string, error)
- func GenerateKey() string
- func GetStateFromContext(ctx fiber.Ctx) string
- func NewBeginAuthHandler(config ...Config) fiber.Handler
- func NewCompleteAuthHandler(config ...Config) fiber.Handler
- func NewLogoutHandler(config ...Config) fiber.Handler
- func NewSessionHandler(config ...Config) fiber.Handler
- func NewStateCookie(name, value string, secure bool) *fasthttp.Cookie
- func Protect(config ...Config) fiber.Handler
- func ProtectedHandler(handler fiber.Handler, config ...Config) fiber.Handler
- func ProviderFromContext(c fiber.Ctx) string
- func Session(config ...Config) fiber.Handler
- func SessionFromContext(c fiber.Ctx) (adapters.GothSession, error)
- func TokenFromContext(c fiber.Ctx) string
- func TokenFromCookie(param string) func(c fiber.Ctx) (string, error)
- func ValidSession(c fiber.Ctx) bool
- type BeginAuthHandler
- type CompleteAuthCompleteHandler
- type Config
- type Environment
- type Error
- type Handler
- type LogoutHandler
- type Params
- type SessionHandler
- type StateCtx
Constants ¶
const ( SessionScope = "session" CodeVerifierScope = "code_verifier" )
Variables ¶
var ( // ErrMissingProviderName is thrown if the provider cannot be determined. ErrMissingProviderName = NewError(http.StatusBadRequest, "missing provider name in request") // ErrMissingSession is thrown if there is no active session. ErrMissingSession = NewError(http.StatusBadRequest, "could not find a matching session for this request") // ErrBadSession is thrown if the session is invalid. ErrBadSession = NewError(http.StatusBadRequest, "session is invalid") // ErrMissingUser is thrown if the user is missing. ErrMissingUser = NewError(http.StatusBadRequest, "missing user") // ErrMissingCookie is thrown if the cookie is missing. ErrMissingCookie = NewError(http.StatusBadRequest, "missing session cookie") // ErrBadRequest is thrown if the request is invalid. ErrBadRequest = NewError(http.StatusBadRequest, "bad request") )
var ConfigDefault = Config{ ErrorHandler: defaultErrorHandler, BeginAuthHandler: BeginAuthHandler{}, CompleteAuthHandler: CompleteAuthCompleteHandler{}, LogoutHandler: LogoutHandler{}, SessionHandler: SessionHandler{}, IndexHandler: defaultIndexHandler, Encryptor: EncryptCookie, Decryptor: DecryptCookie, Expiry: "7h", Extractor: TokenFromCookie("fiber_goth.session"), CookieSameSite: "lax", CompletionURL: "/", LoginURL: "/login", LogoutURL: "/logout", CallbackURL: "/auth", CookiePrefix: "fiber_goth", CookieSecure: false, Environment: Development, }
ConfigDefault is the default config.
Functions ¶
func CodeVerifierFromCookie ¶
CodeVerifierFromCookie returns the code verifier from the cookie.
func ContextWithProvider ¶
ContextWithProvider returns a new request context containing the provider.
func DecryptCookie ¶
DecryptCookie Decrypts a cookie value with specific encryption key.
func EncryptCookie ¶
EncryptCookie Encrypts a cookie value with specific encryption key.
func GetStateFromContext ¶
GetStateFromContext return the state that is returned during the callback.
func NewBeginAuthHandler ¶
NewBeginAuthHandler creates a new middleware handler to start authentication.
func NewCompleteAuthHandler ¶
NewCompleteAuthHandler creates a new middleware handler to complete authentication.
func NewLogoutHandler ¶
NewLogoutHandler returns a new default logout handler.
func NewSessionHandler ¶
NewSessionHandler returns a new default session handler.
func NewStateCookie ¶
NewStateCookie creates a new state cookie.
func ProtectedHandler ¶
ProtectedHandler returns a new default protected handler.
func ProviderFromContext ¶
ProviderFromContext returns the provider from the request context.
func SessionFromContext ¶
func SessionFromContext(c fiber.Ctx) (adapters.GothSession, error)
SessionFromContext returns the session from the request context.
func TokenFromContext ¶
TokenFromContext returns the token from the request context.
func TokenFromCookie ¶
TokenFromCookie returns a function that extracts token from the cookie header.
func ValidSession ¶
ValidSession returns true if the session is valid.
Types ¶
type BeginAuthHandler ¶
type BeginAuthHandler struct{}
BeginAuthHandler is the default handler to begin the authentication process.
type CompleteAuthCompleteHandler ¶
type CompleteAuthCompleteHandler struct{}
CompleteAuthComplete is the default handler to complete the authentication process.
type Config ¶
type Config struct {
// Next defines a function to skip this middleware when returned true.
Next func(c fiber.Ctx) bool
// BeginAuthHandler is the handler to start authentication.
BeginAuthHandler Handler
// CompleteAuthHandler is the handler to complete the authentication.
CompleteAuthHandler Handler
// LogoutHandler is the handler to logout.
LogoutHandler Handler
// SessionHandler is the handler to manage the session.
SessionHandler Handler
// IndexHandler is the handler to display the index.
IndexHandler fiber.Handler
// CompletionFilter that is executed when responses need to returned.
CompletionFilter func(c fiber.Ctx) error
// Secret is the secret used to sign the session.
Secret string
// Expiry is the duration that the session is valid for.
Expiry string
// CookiePrefix is the prefix of the cookies used to store session data.
CookiePrefix string
// CookieSameSite is the SameSite attribute of the cookie.
CookieSameSite string
// CookiePath is the path of the cookie.
CookiePath string
// CookieDomain is the domain of the cookie.
CookieDomain string
// CookieHTTPOnly is the HTTPOnly attribute of the cookie.
CookieHTTPOnly bool
// CookieSecure is the Secure attribute of the cookie.
CookieSecure bool
// Encryptor is the function used to encrypt the session.
Encryptor func(decryptedString, key string) (string, error)
// Decryptor is the function used to decrypt the session.
Decryptor func(encryptedString, key string) (string, error)
// Adapter is the adapter used to store the session.
// Adapter adapters.Adapter
Adapter adapters.Adapter
// LoginURL is the URL to redirect to when the user is not authenticated.
LoginURL string
// LogoutURL is the URL to redirect to when the user logs out.
LogoutURL string
// CallbackURL is the URL to redirect to when the user logs out.
CallbackURL string
// CompletionURL is the default url after completion
CompletionURL string
// ErrorHandler is executed when an error is returned from fiber.Handler.
//
// Optional. Default: DefaultErrorHandler
ErrorHandler fiber.ErrorHandler
// Extractor is the function used to extract the token from the request.
Extractor func(c fiber.Ctx) (string, error)
// Environment is the environment the application is running in.
Environment Environment
}
Config caputes the configuration for running the goth middleware.
func (*Config) CodeVerifierCookieName ¶
CodeVerifierCookieName returns the code verifier cookie name with the prefix.
func (*Config) CookieName ¶
CookieName returns the cookie name with the prefix.
func (*Config) SessionCookieName ¶
SessionCookieName returns the session cookie name with the prefix.
type Environment ¶
type Environment string
Environment represents the environment the application is running in.
const ( // Noop is a no-op function. Noop Environment = "noop" // Development environment. Development Environment = "development" // Testing environment. Testing Environment = "testing" // Staging environment. Staging Environment = "staging" // Production environment. Production Environment = "production" )
type Error ¶
Error is the default error type for the goth middleware.
type LogoutHandler ¶
type LogoutHandler struct{}
LogoutHandler is the default handler for the logout process.
type Params ¶
type Params struct {
// contains filtered or unexported fields
}
Params maps the parameters of the Fiber context to the gothic context.
func (*Params) CodeVerifier ¶
CodeVerifier returns the code verifier for PKCE, if applicable.
type SessionHandler ¶
type SessionHandler struct{}
SessionHandler is the default handler for the session.