Documentation
¶
Overview ¶
Package helper contains helper functions
Package helper provides helper functions
Index ¶
- func CryptoRandomInt(limit int64) (int64, error)
- func CryptoRandomString(length int64) (string, error)
- func GenerateSecureToken(length int) string
- func GenerateTOTPQRCode(username, secret string) (string, error)
- func GetClaimsFromRefreshToken(refreshToken string) (jwt.MapClaims, error)
- func GetEchoJWTConfig() echojwt.Config
- func GetJWTPublicKey() interface{}
- func GetJWTRefreshSigningKey() interface{}
- func GetJWTSigningKey() interface{}
- func GetRequestID(c echo.Context) string
- func GetRequestLogger(c echo.Context) *slog.Logger
- func InArray(needle string, haystack []string) bool
- func SafeAtoi32(s string) (int32, error)
- func StrPtr2Str(str *string) string
- type JwtClaims
- type TokenDetails
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CryptoRandomInt ¶ added in v0.1.0
CryptoRandomInt returns a crypto random integer between 0 and limit, inclusive Copried from https://github.com/go-gitea/gitea/blob/main/modules/util/util.go#L59
func CryptoRandomString ¶ added in v0.1.0
CryptoRandomString generates a crypto random alphanumerical string, each byte is generated by [0,61] range Copied from https://github.com/go-gitea/gitea/blob/main/modules/util/util.go#L70
func GenerateSecureToken ¶ added in v0.1.0
GenerateSecureToken generates a cryptographically secure random token
func GenerateTOTPQRCode ¶ added in v0.2.0
GenerateTOTPQRCode generates a QR code for TOTP setup with the UnderNET logo
func GetClaimsFromRefreshToken ¶ added in v0.0.4
GetClaimsFromRefreshToken gets the claims from the refresh token
func GetEchoJWTConfig ¶ added in v0.0.4
GetEchoJWTConfig returns the echo JWT config
func GetJWTPublicKey ¶ added in v0.0.4
func GetJWTPublicKey() interface{}
GetJWTPublicKey gets the JWT public key
func GetJWTRefreshSigningKey ¶ added in v0.0.4
func GetJWTRefreshSigningKey() interface{}
GetJWTRefreshSigningKey gets the JWT refresh signing key
func GetJWTSigningKey ¶ added in v0.0.4
func GetJWTSigningKey() interface{}
GetJWTSigningKey gets the JWT signing key
func GetRequestID ¶ added in v0.3.0
func GetRequestID(c echo.Context) string
GetRequestID extracts the request ID from the Echo context. Returns "unknown" if no request ID is found.
func GetRequestLogger ¶ added in v0.3.0
GetRequestLogger returns a slog.Logger that automatically includes the request ID from the Echo context in all log entries. If no request ID is found, it uses "unknown".
func SafeAtoi32 ¶ added in v0.0.8
SafeAtoi32 converts a string to int32 with bounds checking
func StrPtr2Str ¶
Types ¶
type JwtClaims ¶
type JwtClaims struct {
UserID int32 `json:"user_id"`
Username string `json:"username"`
RefreshUUID string `json:"refresh_uuid"` // If 2FA is enabled, this will be false until the user has authenticated with TOTPa
Scope string `json:"scope,omitempty"`
Adm int32 `json:"adm,omitempty"`
jwt.RegisteredClaims
}
JwtClaims defines the default claims for JWT
func GetClaimsFromContext ¶
func GetClaimsFromContext(c echo.Context) *JwtClaims
GetClaimsFromContext gets the JWT claims from the echo context
type TokenDetails ¶
type TokenDetails struct {
AccessToken string
RefreshToken string
RefreshUUID string
AtExpires *jwt.NumericDate
RtExpires *jwt.NumericDate
}
TokenDetails defines the details of the tokens
func GenerateToken ¶
func GenerateToken(claims *JwtClaims, t time.Time) (*TokenDetails, error)
GenerateToken generates a JWT token
type Validator ¶ added in v0.0.2
type Validator struct {
// contains filtered or unexported fields
}
Validator is a wrapper around the validator package
func NewValidator ¶ added in v0.0.2
func NewValidator() *Validator
NewValidator returns a new Validator