세션 invalidate될 때 전달하는 인자를 구조체로 변경

This commit is contained in:
2025-09-11 09:38:38 +09:00
parent c73ffda016
commit 0392966760
7 changed files with 45 additions and 432 deletions

View File

@ -14,8 +14,7 @@ import (
)
type Authorization struct {
Account primitive.ObjectID `bson:"a" json:"a"`
invalidated string
Account primitive.ObjectID `bson:"a" json:"a"`
// by authorization provider
Platform string `bson:"p" json:"p"`
@ -30,13 +29,12 @@ func (auth *Authorization) ToStrings() []string {
"p", auth.Platform,
"u", auth.Uid,
"al", auth.Alias,
"inv", auth.invalidated,
"ct", strconv.FormatInt(auth.CreatedTime, 10),
}
}
func (auth *Authorization) Valid() bool {
return len(auth.invalidated) == 0 && !auth.Account.IsZero()
return !auth.Account.IsZero()
}
func MakeAuthrizationFromStringMap(src map[string]string) Authorization {
@ -47,24 +45,28 @@ func MakeAuthrizationFromStringMap(src map[string]string) Authorization {
Platform: src["p"],
Uid: src["u"],
Alias: src["al"],
invalidated: src["inv"],
CreatedTime: ct,
}
}
type Provider interface {
New(*Authorization) (string, error)
RevokeAll(primitive.ObjectID) error
RevokeAll(primitive.ObjectID, bool) ([]string, error)
Query(string) (Authorization, error)
Touch(string) (bool, error)
}
type InvalidatedSession struct {
Account primitive.ObjectID
Infinite bool
}
type Consumer interface {
Query(string) Authorization
Touch(string) (Authorization, error)
IsRevoked(primitive.ObjectID) bool
Revoke(string)
RegisterOnSessionInvalidated(func(primitive.ObjectID))
RegisterOnSessionInvalidated(func(InvalidatedSession))
}
type storagekey string
@ -120,10 +122,6 @@ var errInvalidScheme = errors.New("storageAddr is not valid scheme")
var errSessionStorageMissing = errors.New("session_storageis missing")
func NewConsumer(ctx context.Context, storageAddr string, ttl time.Duration) (Consumer, error) {
if strings.HasPrefix(storageAddr, "mongodb") {
return newConsumerWithMongo(ctx, storageAddr, ttl)
}
if strings.HasPrefix(storageAddr, "redis") {
return newConsumerWithRedis(ctx, storageAddr, ttl)
}
@ -143,10 +141,6 @@ func NewConsumerWithConfig(ctx context.Context, cfg SessionConfig) (Consumer, er
}
func NewProvider(ctx context.Context, storageAddr string, ttl time.Duration) (Provider, error) {
if strings.HasPrefix(storageAddr, "mongodb") {
return newProviderWithMongo(ctx, storageAddr, ttl)
}
if strings.HasPrefix(storageAddr, "redis") {
return newProviderWithRedis(ctx, storageAddr, ttl)
}