auth

package
v0.0.0-...-b33671b Latest Latest
Warning

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

Go to latest
Published: May 21, 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 GetParsedJWT

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

func GetSecretKey

func GetSecretKey() string

func GetUser

func GetUser(ctx context.Context) *platform.User

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 ValidateAPIKey

type ValidateAPIKey func(context.Context, string) (*platform.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