Documentation
¶
Overview ¶
Flatten makes flat, one-dimensional maps from arbitrarily nested ones.
Map keys turn into compound names, like `a.b.1.c` (dotted style) or `a[b][1][c]` (Rails style). It takes input as either JSON strings or Go structures. It (only) knows how to traverse JSON types: maps, slices and scalars.
Or Go maps directly.
t := map[string]interface{}{
"a": "b",
"c": map[string]interface{}{
"d": "e",
"f": "g",
},
"z": 1.4567,
}
flat, err := Flatten(nested, "", RailsStyle)
// output:
// map[string]interface{}{
// "a": "b",
// "c[d]": "e",
// "c[f]": "g",
// "z": 1.4567,
// }
Index ¶
- Variables
- func ExtractToken(r *http.Request) (string, error)
- func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)
- func Setup(c *caddy.Controller) error
- func ValidateToken(uToken string, b AuthBackend) (*jwt.Token, error)
- type AccessRule
- type Auth
- type AuthBackend
- type EncryptionType
- type Rule
- type RuleType
- type SeparatorStyle
Constants ¶
This section is empty.
Variables ¶
var NotValidInputError = errors.New("Not a valid input: map or slice")
Nested input must be a map or slice
Functions ¶
func ExtractToken ¶
ExtractToken will find a JWT token passed one of three ways: (1) as the Authorization header in the form `Bearer <JWT Token>`; (2) as a cookie named `jwt_token`; (3) as a URL query paramter of the form https://example.com?token=<JWT token>
func Flatten ¶
func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)
Flatten generates a flat map from a nested one. The original may include values of type map, slice and scalar, but not struct. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.
func Setup ¶
func Setup(c *caddy.Controller) error
Setup is called by Caddy to parse the config block
func ValidateToken ¶
func ValidateToken(uToken string, b AuthBackend) (*jwt.Token, error)
ValidateToken will return a parsed token if it passes validation, or an error if any part of the token fails validation. Possible errors include malformed tokens, unknown/unspecified signing algorithms, missing secret key, tokens that are not valid yet (i.e., 'nbf' field), tokens that are expired, and tokens that fail signature verification (forged)
Types ¶
type AccessRule ¶
AccessRule represents a single ALLOW/DENY rule based on the value of a claim in a validated token
type Auth ¶
type Auth struct {
Rules []Rule
Next httpserver.Handler
Realm string
}
Auth represents configuration information for the middleware
type AuthBackend ¶
type AuthBackend interface {
GetHMACSecret() (b []byte)
GetRSAPublicKey() (r *rsa.PublicKey)
IsConfigValid() (v bool)
}
AuthBackend represents a backend interface that retrieves secret key material to validate tokens
type EncryptionType ¶
type EncryptionType int
EncryptionType distinguishes between RSA and HMAC key material when stored in a file
const ( // RSA is used to specify a file that contains a PEM-encoded public key RSA EncryptionType = 1 << iota // HMAC is used to specify a file that contains a HMAC-SHA secret HMAC )
type Rule ¶
type Rule struct {
Path string
ExceptedPaths []string
AccessRules []AccessRule
Redirect string
AllowRoot bool
KeyFile string
KeyFileType EncryptionType
}
Rule represents the configuration for a site
type SeparatorStyle ¶
type SeparatorStyle int
The presentation style of keys.
const ( // Separate nested key components with dots, e.g. "a.b.1.c.d" DotStyle SeparatorStyle // Separate ala Rails, e.g. "a[b][c][1][d]" RailsStyle )