Back to godoc.org

Package jwt

v0.2.56
Latest Go to latest

The highest tagged major version is .

Published: Aug 6, 2020 | License: MIT | Module: github.com/pubgo/x

Index

Constants

const (
	// InternalUserID is the auth.id used for internal requests
	InternalUserID string = "internal-sc-user"

	AlgorithmHS256 = "HS256"
)

Variables

var (
	ErrInvalidSigningMethod        = errors.New("invalid signing method type")
	ErrTokenVerification           = errors.New("AUTH: JWT token could not be verified")
	TokenExpired            error  = errors.New("Token is expired")
	TokenNotValidYet        error  = errors.New("Token not active yet")
	TokenMalformed          error  = errors.New("That's not even a token")
	TokenInvalid            error  = errors.New("Couldn't handle this token:")
	SignKey                 string = "qmPlus"
	// ErrMissingSecretKey indicates Secret key is required
	ErrMissingSecretKey = errors.New("secret key is required")

	// ErrForbidden when HTTP status 403 is given
	ErrForbidden = errors.New("you don't have permission to access this resource")

	// ErrMissingAuthenticatorFunc indicates Authenticator is required
	ErrMissingAuthenticatorFunc = errors.New("ginJWTMiddleware.Authenticator func is undefined")

	// ErrMissingLoginValues indicates a user tried to authenticate without username or password
	ErrMissingLoginValues = errors.New("missing Username or Password")

	// ErrFailedAuthentication indicates authentication failed, could be faulty username or password
	ErrFailedAuthentication = errors.New("incorrect Username or Password")

	// ErrFailedTokenCreation indicates JWT Token failed to create, reason unknown
	ErrFailedTokenCreation = errors.New("failed to create JWT Token")

	// ErrExpiredToken indicates JWT token has expired. Can't refresh.
	ErrExpiredToken = errors.New("token is expired")

	// ErrEmptyAuthHeader can be thrown if authing with a HTTP header, the Auth header needs to be set
	ErrEmptyAuthHeader = errors.New("auth header is empty")

	// ErrMissingExpField missing exp field in token
	ErrMissingExpField = errors.New("missing exp field")

	// ErrWrongFormatOfExp field must be float64 format
	ErrWrongFormatOfExp = errors.New("exp must be float64 format")

	// ErrInvalidAuthHeader indicates auth header is invalid, could for example have the wrong Realm name
	ErrInvalidAuthHeader = errors.New("auth header is invalid")

	// ErrEmptyQueryToken can be thrown if authing with URL Query, the query token variable is empty
	ErrEmptyQueryToken = errors.New("query token is empty")

	// ErrEmptyCookieToken can be thrown if authing with a cookie, the token cokie is empty
	ErrEmptyCookieToken = errors.New("cookie token is empty")

	// ErrEmptyParamToken can be thrown if authing with parameter in path, the parameter in path is empty
	ErrEmptyParamToken = errors.New("parameter token is empty")

	// ErrInvalidSigningAlgorithm indicates signing algorithm is invalid, needs to be HS256, HS384, HS512, RS256, RS384 or RS512
	ErrInvalidSigningAlgorithm = errors.New("invalid signing algorithm")

	// ErrNoPrivKeyFile indicates that the given private key is unreadable
	ErrNoPrivKeyFile = errors.New("private key file unreadable")

	// ErrNoPubKeyFile indicates that the given public key is unreadable
	ErrNoPubKeyFile = errors.New("public key file unreadable")

	// ErrInvalidPrivKey indicates that the given private key is invalid
	ErrInvalidPrivKey = errors.New("private key invalid")

	// ErrInvalidPubKey indicates the the given public key is invalid
	ErrInvalidPubKey = errors.New("public key invalid")

	// IdentityKey default identity key
	IdentityKey = "identity"
)

func GetRole

func GetRole(c TokenClaims) (string, error)

GetRole returns the role present in the token claims

type IToken

type IToken interface {
	Create(claims TokenClaims, secret string) (string, error)
	Parse(token string, secret string) (TokenClaims, error)
	IsInternal(token string) error
	CreateClaims() TokenClaims
	Validate(token string) (interface{}, error)
	Refresh(token string) (interface{}, error)
}

type TokenClaims

type TokenClaims = struct {
	Role string
	jwt.StandardClaims
}

TokenClaims holds the JWT token claims

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier