세션 무효화 처리 강화
This commit is contained in:
@ -13,7 +13,8 @@ import (
|
||||
)
|
||||
|
||||
type Authorization struct {
|
||||
Account primitive.ObjectID `bson:"a" json:"a"`
|
||||
Account primitive.ObjectID `bson:"a" json:"a"`
|
||||
invalidated string
|
||||
|
||||
// by authorization provider
|
||||
Platform string `bson:"p" json:"p"`
|
||||
@ -21,9 +22,34 @@ type Authorization struct {
|
||||
Email string `bson:"em" json:"em"`
|
||||
}
|
||||
|
||||
func (auth *Authorization) ToStrings() []string {
|
||||
return []string{
|
||||
"a", auth.Account.Hex(),
|
||||
"p", auth.Platform,
|
||||
"u", auth.Uid,
|
||||
"em", auth.Email,
|
||||
"inv", auth.invalidated,
|
||||
}
|
||||
}
|
||||
|
||||
func (auth *Authorization) Invalidated() bool {
|
||||
return len(auth.invalidated) > 0
|
||||
}
|
||||
|
||||
func MakeAuthrizationFromStringMap(src map[string]string) Authorization {
|
||||
accid, _ := primitive.ObjectIDFromHex(src["a"])
|
||||
return Authorization{
|
||||
Account: accid,
|
||||
Platform: src["p"],
|
||||
Uid: src["u"],
|
||||
Email: src["em"],
|
||||
invalidated: src["inv"],
|
||||
}
|
||||
}
|
||||
|
||||
type Provider interface {
|
||||
New(*Authorization) (string, error)
|
||||
Delete(primitive.ObjectID) error
|
||||
Invalidate(primitive.ObjectID) error
|
||||
Query(string) (Authorization, error)
|
||||
Touch(string) (bool, error)
|
||||
}
|
||||
@ -31,6 +57,7 @@ type Provider interface {
|
||||
type Consumer interface {
|
||||
Query(string) (Authorization, error)
|
||||
Touch(string) (Authorization, error)
|
||||
IsInvalidated(primitive.ObjectID) bool
|
||||
RegisterOnSessionInvalidated(func(primitive.ObjectID))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user