token

package
v0.0.0-...-dae8859 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AccessTokenDuration  time.Duration = time.Hour * 24
	RefreshTokenDuration time.Duration = time.Hour * 24 * 30
)

Variables

This section is empty.

Functions

func New

func New(cnf Config) (*service, error)

Types

type Config

type Config struct {
	PublicKeyFile  string
	PrivateKeyFile string
	Project        string
	SignMethod     string
}

type Jwt

type Jwt struct {
	// contains filtered or unexported fields
}

func NewJwt

func NewJwt(config JwtConfig) (*Jwt, error)

func (*Jwt) Expire

func (j *Jwt) Expire(t string) (string, error)

func (*Jwt) GetClaims

func (j *Jwt) GetClaims(t string) (*UserClaim, error)

func (*Jwt) Parse

func (j *Jwt) Parse(t string, options ...jwt.ParserOption) (*jwt.Token, error)

func (*Jwt) Refresh

func (j *Jwt) Refresh(t string, d time.Duration, nd *jwt.NumericDate) (string, error)

func (*Jwt) Sign

func (j *Jwt) Sign(p *UserClaim) (string, error)

func (*Jwt) SignWithJWtClaims

func (j *Jwt) SignWithJWtClaims(p jwt.Claims) (string, error)

func (*Jwt) Verify

func (j *Jwt) Verify(t string) (bool, error)

func (*Jwt) VerifyAndParse

func (j *Jwt) VerifyAndParse(t string) (*UserClaim, error)

type JwtConfig

type JwtConfig struct {
	PublicKey  []byte
	PrivateKey []byte
	SignMethod string
}

type User

type User struct {
	Id    uuid.UUID `json:"id"`
	Name  string    `json:"name"`
	Email string    `json:"email"`
	Roles []string  `json:"roles"`
}

type UserClaim

type UserClaim struct {
	User
	jwt.RegisteredClaims
	ExpiresIn int64  `json:"expiresIn"`
	Project   string `json:"project"`
	IsAccess  bool   `json:"isAccess"`
	IsRefresh bool   `json:"isRefresh"`
}

func (*UserClaim) Expire

func (c *UserClaim) Expire()

func (*UserClaim) IsExpired

func (c *UserClaim) IsExpired() bool

func (*UserClaim) SetExpireIn

func (c *UserClaim) SetExpireIn(d time.Duration)

func (*UserClaim) Valid

func (c *UserClaim) Valid() error

Jump to

Keyboard shortcuts

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