auth

package
v1.6.7-0...-b28dd99 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// JWTSecret secred from config for signing tokens.
	JWTSecret []byte
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash compares password string with encrypted hash.

func FromContext

func FromContext(ctx context.Context) (*jwt.Token, jwt.MapClaims, error)

FromContext returns token from context.

func GenerateWorkerJWT

func GenerateWorkerJWT(id string) (string, error)

GenerateWorkerJWT generates workers json web token.

func GetWorkerIdentifierByJWT

func GetWorkerIdentifierByJWT(token string) (string, error)

GetWorkerIdentifierByJWT return workers id by token string.

func HashPassword

func HashPassword(passwd Password) (string, error)

HashPassword generates encrypted password from password string

func Init

func Init(secret string)

Init authentication constants from config.

Types

type Authentication

type Authentication struct {
	Identifier string
	JWT        string
}

Authentication holds the identifier/jwt token credentials.

func (*Authentication) GetRequestMetadata

func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error)

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

func NewJWTAuth(alg string) *JWTAuth

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.

func (*JWTAuth) Verifier

func (a *JWTAuth) Verifier() func(http.Handler) http.Handler

Verifier http middleware handler will verify a JWT string from a http request.

type Password

type Password struct {
	Password string
	Cost     int
}

Password defines password to be hashed.

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.

Jump to

Keyboard shortcuts

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