Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateRandomBytes(n int) ([]byte, error)
- func NewRedisClient(address string) *redis.Client
- func NewRedisStore(ctx context.Context, client *redis.Client) (*redisstore.RedisStore, error)
- type Action
- type Claims
- type Config
- type Endpoint
- type Endpoints
- type JWT
- type Redis
- type Token
Constants ¶
const RoleAll = "all"
RoleAll that any authenticated user can access
Variables ¶
var ( // ErrInvalidEndpoint returned when accessing an invalid endpoint ErrInvalidEndpoint = errors.New("accessing invalid endpoint") )
Functions ¶
func GenerateRandomBytes ¶
GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.
func NewRedisClient ¶
func NewRedisClient(address string) *redis.Client
NewRedisClient creates a new redis client
func NewRedisStore ¶
NewRedisStore creates new default RedisStore
Types ¶
type Action ¶ added in v0.0.3
type Action struct { // Can access without authentication Unauthenticated bool // Roles that can access the resource Roles map[string]bool }
Action defines the endpoints action config
type Claims ¶
type Claims struct { jwt.StandardClaims ID int `json:"ID"` Role string `json:"roles"` RandomToken *Token `json:"token"` }
Claims defines the custom JWT claims
type Endpoint ¶ added in v0.0.3
type Endpoint string
Endpoint path
func (Endpoint) CanAccessWithRole ¶ added in v0.0.3
CanAccessWithRole returrns whether the given endpoint is accessible with the users permissions
The method returns false when the action is un-registered or the user doesn't have enough permissions
Returns true otherwise
func (Endpoint) CanAccessWithoutAuth ¶ added in v0.0.3
CanAccessWithoutAuth checks if the endpoint can be accessed without authentication
type JWT ¶
type JWT struct { SecretKey string `env:"GRAC_JWT_SECRET_KEY"` Duration time.Duration `env:"GRAC_JWT_DURATION"` }
JWT is a JSON web token manager
func NewJWTManager ¶
NewJWTManager returns a new JWT manager
func (*JWT) GetSecretKey ¶
GetSecretKey returns secret key to sign jwt
type Redis ¶
type Redis struct { Address string `env:"GRAC_REDIS_ADDRESS"` DefaultSessionID string `env:"GRAC_DEFAULT_SESSION_ID"` SessionDomain string `env:"GRAC_SESSION_DOMAIN"` SessionTimeout int `env:"GRAC_SESSION_TIMEOUT"` SecureCookie bool `env:"GRAC_SECURE_COOKIE"` CSRFTokenLength int `env:"GRAC_CSRF_TOKEN_LENGTH"` }
Redis config
type Token ¶ added in v0.0.3
type Token struct {
Value []byte
}
Token struct hold the token
func (*Token) ToString ¶ added in v0.0.3
ToString converts and returns the string representation of the generated token
func (*Token) ToURLSafeString ¶ added in v0.0.3
ToURLSafeString returns a base64 encoded URL safe random string