Documentation
¶
Index ¶
- Variables
- func BasicAuth(storage string) gin.HandlerFunc
- func CORS() gin.HandlerFunc
- func Cache(p *CacheParams) gin.HandlerFunc
- func IPBasicAuth(ipRange string, authStorage string) gin.HandlerFunc
- func IpCognitoAuth(p *IpCognitoParams) gin.HandlerFunc
- func Limit(limit int, ipRanges ...string) gin.HandlerFunc
- func LimitPerUser(cmdable redis.Cmdable, limit int, key string, expiration time.Duration, ...) gin.HandlerFunc
- func LogFormatter(p gin.LogFormatterParams) string
- func NotFound() gin.HandlerFunc
- func RBAC(fn RBACAuthorizeFunc) gin.HandlerFunc
- type CacheParams
- type CognitoClaims
- type CognitoUser
- type IpCognitoParams
- type JWK
- type Key
- type RBACAuthorizeFunc
- type RedisLimiter
Constants ¶
This section is empty.
Variables ¶
var ErrNoUser = errors.New("missing user in request context")
ErrNoUser indicates there is no user (or the user is nil) in the request's context.
Functions ¶
func BasicAuth ¶
func BasicAuth(storage string) gin.HandlerFunc
BasicAuth middleware for basic authentication in format "user:pass,user2:pass2,user3:pass3"
func Cache ¶ added in v1.0.8
func Cache(p *CacheParams) gin.HandlerFunc
Cache middleware to cache http responses
func IPBasicAuth ¶ added in v1.0.9
func IPBasicAuth(ipRange string, authStorage string) gin.HandlerFunc
IPBasicAuth middleware for: * IP ranges verification in format "192.168.10.1-192.168.10.10,192.168.90.1-192.168.90.10" * basic authentication in format "user:pass,user2:pass2,user3:pass3"
func IpCognitoAuth ¶ added in v1.1.1
func IpCognitoAuth(p *IpCognitoParams) gin.HandlerFunc
IpCognitoAuth middleware for: * IP ranges verification in format "192.168.10.1-192.168.10.10,192.168.90.1-192.168.90.10" * cognito authentication through Authorization Bearer Token Note: If the expiration duration is less than one, the items in the cache never expire (by default), and must be deleted manually. If the cleanup interval is less than one, expired items are not deleted from the cache.
func Limit ¶ added in v1.0.7
func Limit(limit int, ipRanges ...string) gin.HandlerFunc
Limit middleware to limit number of request per second if you pass "inRanges" parameter the limit will be applied only to those IP addresses * IP ranges verification in format "192.168.10.1-192.168.10.10,192.168.90.1-192.168.90.10"
func LimitPerUser ¶ added in v1.1.5
func LimitPerUser(cmdable redis.Cmdable, limit int, key string, expiration time.Duration, groups ...string) gin.HandlerFunc
LimitPerUser middleware is used to limit number of request per second for user. Note: if expiration is set to 0 it means the key has no expiration time.
func LogFormatter ¶ added in v1.1.6
func LogFormatter(p gin.LogFormatterParams) string
LogFormatter builds a logging entry in JSON format containing these fields: - Unix timestamp of the request time - Client's IP address - Accessed API endpoint/path - Request method (GET, POST, PUT, PATCH, DELETE) - Request's response status code - Latency of the request in milliseconds - Response body size in bytes
This function will also look into the gin's context for a user instance. If a CognitoUser instance is found, the formatter will also include the following fields: - Username - User associated group(s)
func RBAC ¶ added in v1.1.5
func RBAC(fn RBACAuthorizeFunc) gin.HandlerFunc
RBAC implements RBAC using the provided authorizer function.
Types ¶
type CacheParams ¶ added in v1.1.9
type CacheParams struct { Cache redis.Cmdable Expire time.Duration Handle gin.HandlerFunc ContentType string }
type CognitoClaims ¶ added in v1.1.5
type CognitoClaims struct { jwt.StandardClaims ClientID string `json:"client_id"` ISS string `json:"iss"` Groups []string `json:"cognito:groups"` }
CognitoClaims claims object for cognito JWT token.
type CognitoUser ¶ added in v1.1.5
type CognitoUser struct { Username string `json:"username,omitempty"` Groups []string `json:"groups,omitempty"` Lookup map[string]struct{} `json:"-"` }
CognitoUser cognito user entity.
func (*CognitoUser) GetGroups ¶ added in v1.1.5
func (cu *CognitoUser) GetGroups() []string
GetGroups get user groups private property
func (*CognitoUser) GetUsername ¶ added in v1.1.5
func (cu *CognitoUser) GetUsername() string
GetUsername get private username property
func (*CognitoUser) IsInGroup ¶ added in v1.1.5
func (cu *CognitoUser) IsInGroup(groups ...string) bool
Checks if user groups contains passed groups
func (*CognitoUser) SetGroups ¶ added in v1.1.5
func (cu *CognitoUser) SetGroups(groups []string)
Set cognito groups for user
func (*CognitoUser) SetUsername ¶ added in v1.1.5
func (cu *CognitoUser) SetUsername(username string)
SetUsername sets username for user
type IpCognitoParams ¶ added in v1.1.8
type IpCognitoParams struct { Srv cognitoidentityprovideriface.CognitoIdentityProviderAPI Cache redis.Cmdable ClientID string IpRange string Expire time.Duration User *CognitoUser }
IpCognitoParams structure epresents middleware parameters
type JWK ¶ added in v1.1.3
type JWK struct { Keys []*Key `json:"keys"` // contains filtered or unexported fields }
JWK JSON web keys list.
type Key ¶ added in v1.1.3
type Key struct { Alg string `json:"alg"` E string `json:"e"` KID string `json:"kid"` KTY string `json:"kty"` N string `json:"n"` Use string `json:"use"` // contains filtered or unexported fields }
Key public key meta data.
type RBACAuthorizeFunc ¶ added in v1.1.5
RBACAuthorizeFunc is the type alias for a RBAC Authorize function signature.
func CasbinRBACAuthorizer ¶ added in v1.1.5
func CasbinRBACAuthorizer(e *casbin.Enforcer) RBACAuthorizeFunc
CasbinRBACAuthorizer uses a provided Casbin enforcer to implement RBAC middleware. This function will look up for a `CognitoUser` instance stored in the request's `gin.Context` using the `user` key, and will attempt to authorize the request using each one of the user's roles. If no match is made, the request will be rejected.
type RedisLimiter ¶ added in v1.1.5
type RedisLimiter struct {
// contains filtered or unexported fields
}
RedisLimiter struct is used for storing limit, expiration and redis client
func NewRedisLimiter ¶ added in v1.1.5
func NewRedisLimiter(cmdable redis.Cmdable, entity string, limit int, expire time.Duration) *RedisLimiter
NewRedisLimiter creates new redis limiter Note: if expire is set to 0 it means the key has no expiration time