vbjwt

package module
v0.1.1-0...-fb2417f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2018 License: Apache-2.0 Imports: 9 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

vbjwt

Build Status codecov Go Report Card GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(userID int, ip string, allowedIPs []string) (token string, success bool)

Generate is the same as `GenerateCtx` but uses the `defaultCtx` as logger.

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.

func Verify

func Verify(token, string, ip string) (userID int, permission int, err error)

Verify is the same as `VerifyCtx` but uses the `defaultCtx` as logger.

func VerifyCtx

func VerifyCtx(token string, ip string, ctx *zap.Logger) (userID int, permission int, err error)

VerifyCtx authenticates the validity of an JWT token against a set of predefined rules. If error interface may be of type `vjwt/(*JWTError)`. Only if there aren't any issues `userID` and `permission` will be filled. Don't forget to check for `vbcore.PermissionBanned` before using.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址