Documentation
¶
Index ¶
- Variables
- func Auth(_cfg AuthConfig) echo.MiddlewareFuncd
- func GetAppID(ctx echo.Context, a *AuthConfig) string
- func GetAppID2(ctx echo.Context, a *AuthConfig) (appID string, notForm bool)
- func GetSign(ctx echo.Context, a *AuthConfig) string
- func GetSign2(ctx echo.Context, a *AuthConfig) (sign string, notForm bool)
- func GetTimestamp(ctx echo.Context, a *AuthConfig) int64
- func GetTimestamp2(ctx echo.Context, a *AuthConfig) (timestamp int64, notForm bool)
- func VerifyLifetime(ctx echo.Context, a *AuthConfig, timestamp int64, sign string) error
- type AuthConfig
- func (a *AuthConfig) Prepare(ctx echo.Context, mustWithSign bool) (appID string, sign string, err error)
- func (a *AuthConfig) SecretGetter() func(ctx echo.Context, appID string) (string, error)
- func (a *AuthConfig) SetDefaults()
- func (a *AuthConfig) SetSecretGetter(getter func(ctx echo.Context, appID string) (string, error)) *AuthConfig
- func (a *AuthConfig) SetSignMaker(signMaker func(data url.Values, secret string) string) *AuthConfig
- func (a *AuthConfig) SignMaker() func(data url.Values, secret string) string
- func (a *AuthConfig) SignRequest(ctx echo.Context, appID string) (sign string, data url.Values, err error)
- func (a *AuthConfig) Verify(ctx echo.Context) error
- type StringerValues
Constants ¶
This section is empty.
Variables ¶
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 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 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 ¶
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) SecretGetter ¶
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 ¶
type StringerValues ¶
func (StringerValues) String ¶
func (v StringerValues) String() string