auth

package module
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 14 Imported by: 0

README

Auth for Tinh Tinh

GitHub Release GitHub License

Description

Auth utilities for Tinh Tinh based on JWT

Install

go get -u github.com/tinh-tinh/auth

Documentation

Index

Constants

View Source
const JWT_TOKEN core.Provide = "JWT_TOKEN"
View Source
const ROLES = "ROLES"
View Source
const USER core.CtxKey = "USER"

Variables

This section is empty.

Functions

func GenerateSalt

func GenerateSalt(salt int) string

func Guard

func Guard(ctrl core.RefProvider, ctx *core.Ctx) bool

func Hash

func Hash(str string, salt ...int) string

func Register

func Register(opt JwtOptions) core.Module

func RoleGuard

func RoleGuard(ctrl core.RefProvider, ctx *core.Ctx) bool

func Roles

func Roles(roles ...string) *core.Metadata

func VerifyHash

func VerifyHash(hashedStr string, plainStr string) bool

Types

type Crypto

type Crypto struct {
	Secret []byte
}

func NewCrypto

func NewCrypto(secret string) *Crypto

func (*Crypto) Decrypt

func (cry *Crypto) Decrypt(cipherText string) string

func (*Crypto) Encrypt

func (cry *Crypto) Encrypt(plainText string) string

type Jwt

type Jwt interface {
	Generate(payload jwt.MapClaims) (string, error)
	Verify(token string) (jwt.MapClaims, error)
}

func InjectJwt

func InjectJwt(module *core.DynamicModule) Jwt

func NewJwt

func NewJwt(opt JwtOptions) Jwt

type JwtHS256

type JwtHS256 struct {
	Secret string
	Opt    SubOptions
}

func NewJwtHS256

func NewJwtHS256(opt JwtOptions) *JwtHS256

func (*JwtHS256) Generate

func (hs256 *JwtHS256) Generate(payload jwt.MapClaims) (string, error)

func (*JwtHS256) Verify

func (hs256 *JwtHS256) Verify(token string) (jwt.MapClaims, error)

type JwtOptions

type JwtOptions struct {
	Alg        jwt.SigningMethod
	Secret     string
	PrivateKey string
	PublicKey  string
	Exp        time.Duration
	IgnoreExp  bool
}

type JwtRS256

type JwtRS256 struct {
	PrivateKey string
	PublicKey  string
	Opt        SubOptions
}

func NewJwtRS256

func NewJwtRS256(opt JwtOptions) *JwtRS256

func (*JwtRS256) Generate

func (rs256 *JwtRS256) Generate(payload jwt.MapClaims) (string, error)

func (*JwtRS256) Verify

func (rs256 *JwtRS256) Verify(token string) (jwt.MapClaims, error)

type SubOptions

type SubOptions struct {
	Exp       time.Duration
	IgnoreExp bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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