token

package
v0.0.0-...-cff5d44 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 8 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

This section is empty.

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(ctx context.Context, t string) (string, error)

func (*Jwt) GetClaims

func (j *Jwt) GetClaims(ctx context.Context, t string) (*UserClaim, error)

func (*Jwt) Parse

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

func (*Jwt) Refresh

func (j *Jwt) Refresh(ctx context.Context, 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(ctx context.Context, t string) (bool, error)

func (*Jwt) VerifyAndParse

func (j *Jwt) VerifyAndParse(ctx context.Context, t string) (*UserClaim, error)

type JwtConfig

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

type Service

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

func New

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

func (*Service) GenerateAccessToken

func (t *Service) GenerateAccessToken(ctx context.Context, u User) (string, error)

func (*Service) GenerateRefreshToken

func (t *Service) GenerateRefreshToken(ctx context.Context, u User) (string, error)

func (*Service) Parse

func (t *Service) Parse(ctx context.Context, token string) (*UserClaim, error)

func (*Service) Verify

func (t *Service) Verify(ctx context.Context, token string) (bool, error)

func (*Service) VerifyAndParse

func (t *Service) VerifyAndParse(ctx context.Context, token string) (*UserClaim, error)

type User

type User struct {
	ID    uuid.UUID `json:"id"`
	Name  string    `json:"name"`
	Email string    `json:"email"`
}

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