sessionguard

package
v0.6.37 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: AGPL-3.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

View Source
const InvalidIPAddress = `invalid ip address`

Variables

This section is empty.

Functions

func EnvKey

func EnvKey(ctx echo.Context, cfg SessionGuardConfig) string

func GetLastLoginInfo

func GetLastLoginInfo(ctx echo.Context, ownerType string, ownerId uint64, sessionId string) (*dbschema.NgingLoginLog, error)

func IgnoreBrowserUA added in v0.6.18

func IgnoreBrowserUA(ctx echo.Context)

func Unpack

func Unpack(ctx echo.Context, ownerType string, ownerIdOrName interface{}, encrypted string) (password string, err error)

func UnsetSession

func UnsetSession(ctx echo.Context, ownerType string)

func Validate

func Validate(ctx echo.Context, lastIP string, ownerType string, ownerId uint64) bool

Validate 验证 session 环境是否安全,避免 cookie 和 session id 被窃取 在非匿名模式下 UserAgent 和 IP 归属地与登录时的一致

Types

type Config added in v0.6.30

type Config struct {
	SessionGuardConfig
	Frontend *SessionGuardConfig `json:"frontend,omitempty"`
}

func GetConfig added in v0.6.30

func GetConfig() *Config

type Environment

type Environment struct {
	UserAgent string                 `json:"ua"`
	Location  ip2regionparser.IpInfo `json:"loc"`
}

func GetEnvFromSession

func GetEnvFromSession(ctx echo.Context, ownerType string) *Environment

func (*Environment) SetSession

func (e *Environment) SetSession(ctx echo.Context, ownerType string)

type PE

type PE struct {
	Password  string `json:"p"`
	EnvKey    string `json:"e"`
	Timestamp int64  `json:"t"`
}

func (*PE) Verify

func (p *PE) Verify(ctx echo.Context, ownerType string, ownerIdOrName interface{}) error

type SessionGuardConfig added in v0.6.30

type SessionGuardConfig struct {
	Expires         int64 `json:"expires"`
	IgnoreBrowserUA bool  `json:"ignoreBrowserUA"`
	IgnoreBrowserIP bool  `json:"ignoreBrowserIP"`
}

func (*SessionGuardConfig) VerifyEnvKey added in v0.6.30

func (cfg *SessionGuardConfig) VerifyEnvKey(ctx echo.Context, ownerType string, ownerIdOrName interface{}, envKey string, dontCheckTime bool) error

Jump to

Keyboard shortcuts

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