auth

package
v0.0.0-...-3138b4c Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	AuthorizationHeader = "Authorization"
	SecretKeyHeader     = "x-access-token"
	APIKeyHeader        = "x-api-key"
)

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(r *http.Request, headerKeyInput ...string) string

func GetCurrentUserID

func GetCurrentUserID(ctx context.Context) int

func GetSecretKey

func GetSecretKey() string

func GetTestJWT

func GetTestJWT(userID int) string

func HostMiddleware

func HostMiddleware() gin.HandlerFunc

func IsValidSecretKey

func IsValidSecretKey(input string) bool

func JWTOrSecretKeyAuthMiddleware

func JWTOrSecretKeyAuthMiddleware(getCurrentUser func(*gin.Context) error) gin.HandlerFunc

func SecretKeyAuthMiddleware

func SecretKeyAuthMiddleware(headerKeyInput ...string) gin.HandlerFunc

func TokenAuthMiddleware

func TokenAuthMiddleware(validateUser ValidateUserFunc, validateAPIKey ValidateAPIKey) gin.HandlerFunc

func TokenValid

func TokenValid(r *http.Request) error

Types

type RawToken

type RawToken struct {
	Authorized    bool    `json:"authorized"`
	UserID        int     `json:"userId"`
	OrgType       string  `json:"orgType"`
	OrgID         int     `json:"orgId"`
	FirstName     string  `json:"given_name"`
	LastName      string  `json:"family_name"`
	Email         string  `json:"email"`
	Role          string  `json:"role"`
	Audience      string  `json:"aud"`
	Expiration    int64   `json:"exp"`
	IAT           float64 `json:"iat"`
	Issuer        string  `json:"iss"`
	Sub           string  `json:"sub"`
	JTI           string  `json:"jti"`
	EmailVerified bool    `json:"email_verified"`
	Hd            string  `json:"hd"`
	Data          string  `json:"data"`
}

func ParseJWT

func ParseJWT(tokenString string) (RawToken, error)

type User

type User struct {
	ID        int    `json:"id,omitempty"`
	Username  string `json:"username,omitempty"`
	Email     string `json:"email,omitempty"`
	FirstName string `json:"firstName,omitempty"`
	LastName  string `json:"lastName,omitempty"`

	CreatedAt time.Time `json:"createdAt,omitempty"`
	UpdatedAt time.Time `json:"updatedAt,omitempty"`
}

func GetParsedJWT

func GetParsedJWT(req *http.Request) (*User, error)

func GetUser

func GetUser(ctx context.Context) *User

type ValidateAPIKey

type ValidateAPIKey func(context.Context, string) (*User, error)

type ValidateUserFunc

type ValidateUserFunc func(UserID int) error

Jump to

Keyboard shortcuts

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