auth

package
v0.0.0-...-e3d9ab2 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthState0Guest          = 0
	AuthState1AnyUser        = 1
	AuthState2UserOfChain    = 2
	AuthState3AdminChainUser = 3
	AuthState4RootUser       = 4
)

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(c *gin.Context, db *gorm.DB, minimumAuthState int, chainUID string) (ok bool, authUser *models.User, chain *models.Chain)

There are 4 different states to authenticate 0. Guest - this middleware is then not required 1. User of a different/unknown chain 2. User connected to the chain in question 3. Admin User of the chain in question 4. Root User

func AuthenticateEvent

func AuthenticateEvent(c *gin.Context, db *gorm.DB, eventUID string) (ok bool, authUser *models.User, event *models.Event)

func AuthenticateToken

func AuthenticateToken(db *gorm.DB, tokenString string) (*models.User, bool, error)

func AuthenticateUserOfChain

func AuthenticateUserOfChain(c *gin.Context, db *gorm.DB, chainUID, userUID string) (ok bool, user, authUser *models.User, chain *models.Chain)

This runs Authenticate and defines minimumAuthState depending on the input Any of the following rules pass authentication

1. authUser UID is the same as the given userUID 2. authUser is a chain admin of chain and user is part that same chain 3. authUser is a root admin

func CookieRemove

func CookieRemove(c *gin.Context)

func CookieSet

func CookieSet(c *gin.Context, userUID, token string)

func JwtGenerate

func JwtGenerate(user *models.User) (string, error)

func OtpCreate

func OtpCreate(db *gorm.DB, userID uint) (string, error)

func OtpDeleteOld

func OtpDeleteOld(db *gorm.DB)

func OtpVerify

func OtpVerify(db *gorm.DB, userEmail, otp string) (*models.User, string, error)

Returns the user before it was verified

func TokenReadFromRequest

func TokenReadFromRequest(c *gin.Context) (string, bool)

Types

type MyJwtClaims

type MyJwtClaims struct {
	jwt.RegisteredClaims
	Pepper int `json:"pepper"`
}

Jump to

Keyboard shortcuts

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