utils

package
v0.0.0-...-486f8e0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLAIM_EXPIRY_MINS = 30
)
View Source
const (
	USERNAME_HEADER = "username"
)

Variables

View Source
var (
	ErrMissingMetadata = status.Errorf(codes.InvalidArgument, "missing metadata")
	ErrInvalidToken    = status.Errorf(codes.Unauthenticated, "invalid token")
	ErrTokenGeneration = status.Errorf(codes.Unauthenticated, "unable to generate token")
	ErrInvalidClaim    = status.Errorf(codes.Unauthenticated, "invalid claim")
	ErrTokenNotFound   = status.Errorf(codes.InvalidArgument, "token not found")
)

Functions

func AuthRequired

func AuthRequired(method string) bool

func CheckPasswordHash

func CheckPasswordHash(password, hashedPassword string) bool

func ConvertToProtoChats

func ConvertToProtoChats(mongoChat models.Chat) *pb.ChatResponse

func GenerateToken

func GenerateToken(username, userId string) (string, error)

func HashPassword

func HashPassword(password string) (string, error)

func StreamInterceptor

func StreamInterceptor(srv any, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error

func UnaryInterceptor

func UnaryInterceptor(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error)

func ValidateToken

func ValidateToken(tokenString string) (string, string, error)

Types

type UserClaim

type UserClaim struct {
	jwt.RegisteredClaims
	Username string
	UserID   string
}

Jump to

Keyboard shortcuts

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