Documentation
¶
Overview ¶
Package jwt provides the hiboot starter for injectable jwt dependency
Index ¶
Constants ¶
const (
// DefaultContextKey is the default context key for JWT
DefaultContextKey = "jwt"
)
const (
// Profile is the profile of jwt, it should be as same as the package name
Profile = "jwt"
)
Variables ¶
This section is empty.
Functions ¶
func FromAuthHeader ¶ added in v1.8.4
FromAuthHeader extracts the JWT token from the Authorization header.
Types ¶
type Config ¶ added in v1.8.4
type Config struct {
ValidationKeyGetter jwt.Keyfunc
ContextKey string
ErrorHandler errorHandler
CredentialsOptional bool
Extractor TokenExtractor
Debug bool
EnableAuthOnOptions bool
SigningMethod jwt.SigningMethod
}
Config is a struct for specifying configuration options for the jwt middleware.
type Controller ¶
type Controller struct {
at.JwtRestController
}
Controller is the base controller for jwt.RestController
type Middleware ¶ added in v0.9.3
type Middleware struct {
Config Config
}
Middleware derived from github.com/hidevopsio/middleware/jwt/Middleware
func NewJwtMiddleware ¶
func NewJwtMiddleware(cfg ...Config) *Middleware
NewJwtMiddleware New constructs a new Secure instance with supplied options.
func (*Middleware) CheckJWT ¶ added in v0.9.3
func (m *Middleware) CheckJWT(ctx ictx.Context) error
CheckJWT the main functionality, checks for token
func (*Middleware) Serve ¶ added in v0.9.3
func (m *Middleware) Serve(ctx context.Context)
Serve the middleware's action
type Properties ¶
type Properties struct {
at.ConfigurationProperties `value:"jwt"`
at.AutoWired
PrivateKeyPath string `json:"private_key_path" default:"config/ssl/app.rsa"`
PublicKeyPath string `json:"public_key_path" default:"config/ssl/app.rsa.pub"`
}
Properties the jwt properties
type Token ¶
type Token interface {
Generate(payload Map, expired int64, unit time.Duration) (string, error)
VerifyKey() *rsa.PublicKey
}
Token is the token interface
type TokenExtractor ¶ added in v1.8.4
TokenExtractor is a function that takes a context as input and returns either a token or an error.
func FromFirst ¶ added in v1.8.4
func FromFirst(extractors ...TokenExtractor) TokenExtractor
FromFirst returns a function that runs multiple token extractors and takes the first token it finds
func FromParameter ¶ added in v1.8.4
func FromParameter(param string) TokenExtractor
FromParameter returns a function that extracts the token from the specified query string parameter
type TokenProperties ¶ added in v0.11.0
type TokenProperties struct {
at.Scope `value:"request"`
// contains filtered or unexported fields
}
TokenProperties is the struct for parse jwt token properties
func (*TokenProperties) Get ¶ added in v0.11.0
func (p *TokenProperties) Get(propName string) (propVal string)
Get is an util that parsing JWT token and return single property from jwt.MapClaims
func (*TokenProperties) GetAll ¶ added in v0.11.0
func (p *TokenProperties) GetAll() (propMap map[string]interface{}, ok bool)
GetAll is an util that parsing JWT token and return all properties from jwt.MapClaims