Documentation
¶
Index ¶
- Variables
- func CheckPasswordHash(password, hash string) bool
- func FromContext(ctx context.Context) (*jwt.Token, jwt.MapClaims, error)
- func GenerateWorkerJWT(id string) (string, error)
- func GetWorkerIdentifierByJWT(token string) (string, error)
- func HashPassword(passwd Password) (string, error)
- func Init(secret string)
- type Authentication
- type JWTAuth
- type Password
- type UserClaims
- type WorkerClaims
Constants ¶
This section is empty.
Variables ¶
var ( // JWTSecret secred from config for signing tokens. JWTSecret []byte )
Functions ¶
func CheckPasswordHash ¶
CheckPasswordHash compares password string with encrypted hash.
func FromContext ¶
FromContext returns token from context.
func GenerateWorkerJWT ¶
GenerateWorkerJWT generates workers json web token.
func GetWorkerIdentifierByJWT ¶
GetWorkerIdentifierByJWT return workers id by token string.
func HashPassword ¶
HashPassword generates encrypted password from password string
Types ¶
type Authentication ¶
Authentication holds the identifier/jwt token credentials.
func (*Authentication) GetRequestMetadata ¶
GetRequestMetadata gets the current request metadata.
func (*Authentication) RequireTransportSecurity ¶
func (a *Authentication) RequireTransportSecurity() bool
RequireTransportSecurity indicates whether the credentials requires transport security.
type JWTAuth ¶
type JWTAuth struct {
// contains filtered or unexported fields
}
JWTAuth is JWT authenticator that provides middleware handlers and encoding/decoding functions for JWT signing.
var JWT *JWTAuth
JWT is exposed JWT authenticator with middlewares to verify access tokens.
func NewJWTAuth ¶
NewJWTAuth creates new JWTAuth authenticator instance.
func (*JWTAuth) CreateJWT ¶
func (a *JWTAuth) CreateJWT(c UserClaims) (string, error)
CreateJWT returns an access token for provided user claims.
func (*JWTAuth) CreateWorkerJWT ¶
func (a *JWTAuth) CreateWorkerJWT(c WorkerClaims) (string, error)
CreateWorkerJWT returns an access token for provided worker claims.
type UserClaims ¶
type UserClaims struct { ID uint `json:"id"` Login string `json:"login"` Email string `json:"email"` Name string `json:"name"` Avatar string `json:"avatar"` Role string `json:"role"` jwt.StandardClaims }
UserClaims represent the claims parsed from JWT access token.
func UserClaimsFromJWT ¶
func UserClaimsFromJWT(tokenString string) (UserClaims, error)
UserClaimsFromJWT returns user data included in token.
func (*UserClaims) ParseClaims ¶
func (c *UserClaims) ParseClaims(claims jwt.MapClaims) error
ParseClaims parses JWT claims into UserClaims.
type WorkerClaims ¶
type WorkerClaims struct { ID string `json:"id"` Addr string `json:"addr"` jwt.StandardClaims }
WorkerClaims represent the claims parsed from JWT access token on worker node connection.
func WorkerClaimsFromJWT ¶
func WorkerClaimsFromJWT(tokenString string) (WorkerClaims, error)
WorkerClaimsFromJWT returns user data included in token.
func (*WorkerClaims) ParseClaims ¶
func (c *WorkerClaims) ParseClaims(claims jwt.MapClaims) error
ParseClaims parses JWT claims into WorkerClaims.