Documentation ¶
Index ¶
Constants ¶
View Source
const (
ContextKeyRoles = "roles"
)
Variables ¶
View Source
var ( // Errors ErrTokenMissing = echo.NewHTTPError(http.StatusBadRequest, "Missing or malformed Firebase AuthID TOKEN") ErrTokenInvalid = echo.NewHTTPError(http.StatusUnauthorized, "Invalid or expired Firebase AuthID TOKEN") // DefaultFirebaseAuthConfig is the default auth middleware config. DefaultFirebaseAuthConfig = Config{ Skipper: middleware.DefaultSkipper, ContextIDKey: "id-key", ContextUserKey: "user", ContextUserIDKey: "userID", TokenLookup: "header:" + echo.HeaderAuthorization, AuthScheme: "Bearer", } )
Functions ¶
func FirebaseAuth ¶
func FirebaseAuth() echo.MiddlewareFunc
FirebaseAuth returns a JSON Web Token (JWT) auth middleware.
For valid token, it sets the user in context and calls next handler. For invalid token, it returns "401 - Unauthorized" error. For missing token, it returns "400 - Bad Request" error.
func GetContextValue ¶ added in v0.2.1
func GetContextValueMap ¶ added in v0.2.2
func WithConfig ¶
func WithConfig(config Config) echo.MiddlewareFunc
WithConfig returns a FirebaseAuth middleware with config. See: `FirebaseAuth()`.
Types ¶
type Config ¶
type Config struct { // Skipper defines a function to skip middleware. Skipper middleware.Skipper // ID key to store user information from the token into context. // Optional. Default value "id-key". ContextIDKey string // Context key to store user information from the user into context. // Optional. Default value "user". ContextUserKey string ContextUserIDKey string GetRoles GetRolesFunc // TokenLookup is a string in the form of "<source>:<name>" that is used // to extract token from the request. // Optional. Default value "header:Authorization". // Possible values: // - "header:<name>" // - "query:<name>" // - "cookie:<name>" TokenLookup string // AuthScheme to be used in the Authorization header. // Optional. Default value "Bearer". AuthScheme string CredentialJSON []byte }
Config defines the config for Firebase Auth JWT middleware.
type GetRolesFunc ¶ added in v0.2.4
GetRolesFunc is an external closure function that can retrieve roles by email.
Click to show internal directories.
Click to hide internal directories.