Documentation
¶
Index ¶
- func Generate(userID int, ip string, allowedIPs []string) (token string, success bool)
- func GenerateCtx(userID int, ip string, allowedIPs []string, ctx *zap.Logger) (token string, success bool)
- func GenerateNonDefault(issuer string, userID int, expires time.Time, ip string, allowedIPs []string) (token string, success bool)
- func GenerateNonDefaultCtx(issuer string, userID int, expires time.Time, ip string, allowedIPs []string, ...) (token string, success bool)
- func Init(isProduction bool, defaultSigningkey string, signingKeys map[string]string, ...) error
- func Verify(token, string, ip string) (userID int, permission int, err error)
- func VerifyCtx(token string, ip string, ctx *zap.Logger) (userID int, permission int, err error)
- type VBClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateCtx ¶
func GenerateCtx(userID int, ip string, allowedIPs []string, ctx *zap.Logger) (token string, success bool)
GenerateCtx creates a new signed token and saves it's JTI into the database
func GenerateNonDefault ¶
func GenerateNonDefault(issuer string, userID int, expires time.Time, ip string, allowedIPs []string) (token string, success bool)
GenerateNonDefault is the same as `GenerateNonDefaultCtx` but uses the `defaultCtx` as logger.
func GenerateNonDefaultCtx ¶
func GenerateNonDefaultCtx(issuer string, userID int, expires time.Time, ip string, allowedIPs []string, ctx *zap.Logger) (token string, success bool)
GenerateNonDefaultCtx creates a new signed token and saves it's JTI into the database
func Init ¶
func Init(isProduction bool, defaultSigningkey string, signingKeys map[string]string, ctx *zap.Logger) error
Init prepares `vbjwt` for handling authentication later. `isProduction` indicates if the default `Generate` methods use "vikebot_production" or "vikebot_qa" as JWT issuer. The `signingKeys` map contains all ever used keys as [id]hexkeyformat. If you want to deprecate a single key-id remove the hexkey and use a empty string.
Types ¶
type VBClaims ¶
type VBClaims struct { AllowedIPs []string `json:"allowed_ips"` jwt.StandardClaims }
VBClaims is vikebot's custom `Claims` interface, containing allowed origin (e.g. remot) IPs allowed to use this JWT. UserID is stored as `int` in the Subject. The `jti` (JWT-ID) can be used to determine blacklisted tokens.