utils

package
v0.0.0-...-fe975ab Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RefreshTokenDuration = 24 * 2 // 2 days
	AccessTokenDuration  = 6      // 6 hours
)

Variables

View Source
var ResponsesModel = Responses{}

Functions

This section is empty.

Types

type AccessTokenRawPayload

type AccessTokenRawPayload struct {
	ID       primitive.ObjectID `json:"id"`
	Username string             `json:"username"`
	Scopes   []string           `json:"scopes"`
}

AccessTokenRawPayload create a custom type for the claims

type JWT

type JWT[T RawPayload] struct{}

JWT create a generic JWT struct

func (*JWT[T]) GenerateToken

func (j *JWT[T]) GenerateToken(payload T) (string, error)

GenerateToken generate the payload for the jwt

func (*JWT[T]) GetInstance

func (j *JWT[T]) GetInstance() *JwtInstance

GetInstance get the instance of the JWT

func (*JWT[T]) ValidateToken

func (j *JWT[T]) ValidateToken(tokenString string) (*JwtPayload[T], error)

ValidateToken validate the token

type JwtInstance

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

type JwtPayload

type JwtPayload[T RawPayload] struct {
	Payload *T `json:"payload"`
	jwt.RegisteredClaims
}

type Password

type Password struct{}

func (*Password) Hash

func (p *Password) Hash(password string) (string, error)

func (*Password) Verify

func (p *Password) Verify(password, hash string) error

type RawPayload

type RawPayload interface {
	AccessTokenRawPayload | RefreshTokenRawPayload
}

type RefreshTokenRawPayload

type RefreshTokenRawPayload struct {
	AccessToken string `json:"access_token"`
}

RefreshTokenRawPayload create a custom type for the claims

type Responses

type Responses struct {
	Status    int        `json:"status"`
	Message   string     `json:"message"`
	Data      *fiber.Map `json:"data"`
	Timestamp time.Time  `json:"timestamp"`
}

func (*Responses) BadRequest

func (r *Responses) BadRequest(ctx *fiber.Ctx, message string) error

func (*Responses) Custom

func (r *Responses) Custom(ctx *fiber.Ctx, status int, message string, data *fiber.Map) error

func (*Responses) Error

func (r *Responses) Error(ctx *fiber.Ctx, status int, message string) error

func (*Responses) Forbidden

func (r *Responses) Forbidden(ctx *fiber.Ctx) error

func (*Responses) GatewayTimeout

func (r *Responses) GatewayTimeout(ctx *fiber.Ctx) error

func (*Responses) InternalServerError

func (r *Responses) InternalServerError(ctx *fiber.Ctx) error

func (*Responses) NotFound

func (r *Responses) NotFound(ctx *fiber.Ctx) error

func (*Responses) ServiceUnavailable

func (r *Responses) ServiceUnavailable(ctx *fiber.Ctx) error

func (*Responses) Success

func (r *Responses) Success(ctx *fiber.Ctx, data *fiber.Map) error

func (*Responses) Unauthorized

func (r *Responses) Unauthorized(ctx *fiber.Ctx, message string) error

type Tokens

type Tokens struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

func RefreshTokens

func RefreshTokens(tokens Tokens) (*Tokens, error)

Jump to

Keyboard shortcuts

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