authentication

package
v0.0.0-...-7fab21c Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SECRETKEY = []byte(cfg.SecretKey)

Functions

func DecodeAccessToken

func DecodeAccessToken(token string, db *gorm.DB) (*models.User, *string)

func DecodeRefreshToken

func DecodeRefreshToken(token string) bool

func GenerateAccessToken

func GenerateAccessToken(userId uuid.UUID) string

func GenerateRefreshToken

func GenerateRefreshToken() string

func GetUser

func GetUser(token string, db *gorm.DB) (*models.User, *string)

func RemoveAuthCookie

func RemoveAuthCookie(c *fiber.Ctx, cookieType CookieType)

func SetAuthCookie

func SetAuthCookie(c *fiber.Ctx, cookieType CookieType, token string)

func ValidateAndFetchGoogleUser

func ValidateAndFetchGoogleUser(ctx context.Context, oauthConfig *oauth2.Config, db *gorm.DB, code string) (*models.User, error)

Types

type AccessTokenPayload

type AccessTokenPayload struct {
	UserId uuid.UUID `json:"user_id"`
	jwt.RegisteredClaims
}

type CookieType

type CookieType string
const (
	AccessToken  CookieType = "accessToken"
	RefreshToken CookieType = "refreshToken"
)

type GoogleUserInfo

type GoogleUserInfo struct {
	Email           string `json:"email"`
	Name            string `json:"name"`
	GoogleID        string `json:"id"`
	GivenName       string `json:"given_name"`
	Family          string `json:"family_name"`
	Avatar          string `json:"picture"`
	IsEmailVerified bool   `json:"verified_email"`
}

GoogleUserInfo represents the structure of user data from Google

type Middleware

type Middleware struct {
	DB *gorm.DB
}

func (Middleware) Admin

func (mid Middleware) Admin(c *fiber.Ctx) error

func (Middleware) AuthMiddleware

func (mid Middleware) AuthMiddleware(c *fiber.Ctx) error

func (Middleware) RateLimiter

func (mid Middleware) RateLimiter(c *fiber.Ctx) error

type RefreshTokenPayload

type RefreshTokenPayload struct {
	Data string `json:"data"`
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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