gateway

package
v0.0.0-...-1985c56 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package gateway implments various auth logic used across noebs services

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCreateDbRow = errors.New("unable to create a new db row/column")
)

Functions

func GenerateAPIKey

func GenerateAPIKey() (string, error)

func GenerateSecretKey

func GenerateSecretKey(n int) ([]byte, error)

GenerateSecretKey generates secret key for jwt signing

func Instrumentation

func Instrumentation() gin.HandlerFunc

func OptionsMiddleware

func OptionsMiddleware(c *gin.Context)

OptionsMiddleware for cors headers

Types

type Cards

type Cards struct {
	gorm.Model
	PAN       string `json:"pan" binding:"required"`
	Expdate   string `json:"exp_date" binding:"required"`
	IsPrimary bool   `json:"is_primary" binding:"required"`
}

type ErrorResponse

type ErrorResponse struct {
	Code    uint
	Message string
}

type GetRedisClient

type GetRedisClient func(string) *redis.Client

type JWT

type JWT struct {
	gorm.Model
	SecretKey string
}

type JWTAuth

type JWTAuth struct {
	Key []byte
}

JWTAuth provides an encapsulation for jwt auth

func (*JWTAuth) AuthMiddleware

func (a *JWTAuth) AuthMiddleware() gin.HandlerFunc

AuthMiddleware is a JWT authorization middleware. It is used in our consumer services to get a username from the payload (maybe change it to mobile number at somepoint)

func (*JWTAuth) GenerateJWT

func (j *JWTAuth) GenerateJWT(serviceID string) (string, error)

GenerateJWT generates a JWT standard token with default values hardcoded. FIXME

func (*JWTAuth) GenerateJWTWithClaim

func (j *JWTAuth) GenerateJWTWithClaim(username string, tk TokenClaims) (string, error)

GenerateJWTWithClaim generates a JWT standard token with default values hardcoded. FIXME

func (*JWTAuth) Init

func (j *JWTAuth) Init()

Init initializes jwt auth

func (*JWTAuth) VerifyJWT

func (j *JWTAuth) VerifyJWT(tokenString string) (*TokenClaims, error)

VerifyJWT giving a jwt token and a secret it validates the token against a hard coded TokenClaims struct

type Service

type Service struct {
	gorm.Model
	ServiceName string `gorm:"index"`
	Password    string
	JWT         JWT
	JWTID       int
}

type TokenClaims

type TokenClaims struct {
	Username string `json:"username"`
	jwt.StandardClaims
}

TokenClaims noebs standard claim

func (TokenClaims) Default

func (t TokenClaims) Default(username string) jwt.Claims

Default populate token claims with default values

type UserLogin

type UserLogin struct {
	Username string `binding:"required" json:"username"`
	Password string `binding:"required" json:"password"`
}

type UserModel

type UserModel struct {
	gorm.Model
	Username string `binding:"min=3" json:"username"`
	Password string `binding:"required,min=8,max=20" json:"password"`

	Fullname  string `json:"fullname"`
	Birthday  string `json:"birthday"`
	Mobile    string `json:"mobile" binding:"required,len=10" gorm:"unique_index"`
	Email     string `json:"email"`
	Password2 string `binding:"required,eqfield=Password,min=8,max=20" json:"password2"`

	Card []Cards
	// contains filtered or unexported fields
}

func (*UserModel) HashPassword

func (u *UserModel) HashPassword() error

func (*UserModel) SanitizeName

func (u *UserModel) SanitizeName()

Jump to

Keyboard shortcuts

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