mwapp

package
v0.0.0-...-5cfb982 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAuthAppConfig = AuthConfig{
		HeaderAppIDKey: `X-App-ID`,
		HeaderSignKey:  `X-App-Sign`,
		HeaderTimeKey:  `X-App-Timestamp`,
		FormAppIDKey:   `appID`,
		FormSignKey:    `sign`,
		FormTimeKey:    `timestamp`,
		LifeSeconds:    3600,
		// contains filtered or unexported fields
	}
)

Functions

func Auth

func Auth(_cfg AuthConfig) echo.MiddlewareFuncd

func GetAppID

func GetAppID(ctx echo.Context, a *AuthConfig) string

GetAppID returns the AppID of the current request. It first checks the form data, and if not found, it checks the header. The AppID is trimmed of whitespace.

func GetAppID2

func GetAppID2(ctx echo.Context, a *AuthConfig) (appID string, notForm bool)

func GetSign

func GetSign(ctx echo.Context, a *AuthConfig) string

GetSign returns the sign of the current request. It first checks the form data, and if not found, it checks the header. The sign is trimmed of whitespace.

func GetSign2

func GetSign2(ctx echo.Context, a *AuthConfig) (sign string, notForm bool)

func GetTimestamp

func GetTimestamp(ctx echo.Context, a *AuthConfig) int64

GetTimestamp returns the timestamp of the current request. It first checks the form data, and if not found, it checks the header. The timestamp is parsed as an int64. If the timestamp is not found or is invalid, it returns 0.

The timestamp is expected to be in seconds since the Unix epoch (January 1, 1970, 00:00:00 UTC).

The timestamp is used to verify the lifetime of the request. If the request is older than the lifetime specified in the AuthConfig, the request is rejected.

func GetTimestamp2

func GetTimestamp2(ctx echo.Context, a *AuthConfig) (timestamp int64, notForm bool)

func VerifyLifetime

func VerifyLifetime(ctx echo.Context, a *AuthConfig, timestamp int64, sign string) error

VerifyLifetime verifies the lifetime of the current request. If the request has a sign and the lifetime is specified in the AuthConfig, it checks if the request is older than the lifetime. If the request is older than the lifetime, it returns an error. The error is set to be in the zone of the FormTimeKey of the AuthConfig.

Types

type AuthConfig

type AuthConfig struct {
	// Header 字段名
	HeaderAppIDKey string
	HeaderSignKey  string
	HeaderTimeKey  string
	// Form 字段名
	FormAppIDKey string
	FormSignKey  string
	FormTimeKey  string
	// 有效期
	LifeSeconds int64
	// contains filtered or unexported fields
}

func NewAuthConfig

func NewAuthConfig() *AuthConfig

func (*AuthConfig) Prepare

func (a *AuthConfig) Prepare(ctx echo.Context, mustWithSign bool) (appID string, sign string, err error)

func (*AuthConfig) SecretGetter

func (a *AuthConfig) SecretGetter() func(ctx echo.Context, appID string) (string, error)

func (*AuthConfig) SetDefaults

func (a *AuthConfig) SetDefaults()

func (*AuthConfig) SetSecretGetter

func (a *AuthConfig) SetSecretGetter(getter func(ctx echo.Context, appID string) (string, error)) *AuthConfig

func (*AuthConfig) SetSignMaker

func (a *AuthConfig) SetSignMaker(signMaker func(data url.Values, secret string) string) *AuthConfig

func (*AuthConfig) SignMaker

func (a *AuthConfig) SignMaker() func(data url.Values, secret string) string

func (*AuthConfig) SignRequest

func (a *AuthConfig) SignRequest(ctx echo.Context, appID string) (sign string, data url.Values, err error)

func (*AuthConfig) Verify

func (a *AuthConfig) Verify(ctx echo.Context) error

type StringerValues

type StringerValues url.Values

func (StringerValues) String

func (v StringerValues) String() string

Jump to

Keyboard shortcuts

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