2025-02-12 01:51:46 +00:00
|
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
2025-02-13 11:06:51 +00:00
|
|
|
|
|
|
|
|
|
"code.30cm.net/digimon/app-cloudep-permission-server/pkg/domain/entity"
|
2025-02-12 01:51:46 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// TokenRepo 管理Token
|
|
|
|
|
type TokenRepo interface {
|
|
|
|
|
Create
|
|
|
|
|
Get
|
|
|
|
|
Delete
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Create interface {
|
|
|
|
|
// Create 建立新的 Token
|
|
|
|
|
Create(ctx context.Context, token entity.Token) error
|
|
|
|
|
// CreateOneTimeToken 建立臨時(一次性)Token,並指定有效期限
|
|
|
|
|
CreateOneTimeToken(ctx context.Context, key string, ticket entity.Ticket, et time.Duration) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Get interface {
|
|
|
|
|
// GetAccessTokenByOneTimeToken 根據一次性 Token 獲取對應的存取 Token
|
|
|
|
|
GetAccessTokenByOneTimeToken(ctx context.Context, oneTimeToken string) (entity.Token, error)
|
|
|
|
|
// GetAccessTokenByID 根據 Token ID 獲取對應的存取 Token
|
|
|
|
|
GetAccessTokenByID(ctx context.Context, id string) (entity.Token, error)
|
|
|
|
|
// GetAccessTokensByUID 根據用戶 ID 獲取該用戶的所有存取 Token
|
|
|
|
|
GetAccessTokensByUID(ctx context.Context, uid string) ([]entity.Token, error)
|
|
|
|
|
// GetAccessTokenCountByUID 根據用戶 ID 獲取該用戶的存取 Token 數量
|
|
|
|
|
GetAccessTokenCountByUID(ctx context.Context, uid string) (int, error)
|
|
|
|
|
// GetAccessTokensByDeviceID 根據裝置 ID 獲取該裝置的所有存取 Token
|
|
|
|
|
GetAccessTokensByDeviceID(ctx context.Context, deviceID string) ([]entity.Token, error)
|
|
|
|
|
// GetAccessTokenCountByDeviceID 根據裝置 ID 獲取該裝置的存取 Token 數量
|
|
|
|
|
GetAccessTokenCountByDeviceID(ctx context.Context, deviceID string) (int, error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Delete interface {
|
|
|
|
|
// Delete 刪除指定的 Token
|
|
|
|
|
Delete(ctx context.Context, token entity.Token) error
|
|
|
|
|
// DeleteAccessTokenByID 根據 Token ID 批量刪除存取 Token
|
|
|
|
|
DeleteAccessTokenByID(ctx context.Context, ids []string) error
|
|
|
|
|
// DeleteAccessTokensByUID 根據用戶 ID 刪除該用戶的所有存取 Token
|
|
|
|
|
DeleteAccessTokensByUID(ctx context.Context, uid string) error
|
|
|
|
|
// DeleteAccessTokensByDeviceID 根據裝置 ID 刪除該裝置的所有存取 Token
|
|
|
|
|
DeleteAccessTokensByDeviceID(ctx context.Context, deviceID string) error
|
|
|
|
|
// DeleteOneTimeToken 批量刪除一次性 Token
|
|
|
|
|
DeleteOneTimeToken(ctx context.Context, ids []string, tokens []entity.Token) error
|
|
|
|
|
}
|