feat: JWT Claims 新增资产字段,登录 token 携带当前资产上下文

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-04-16 15:55:41 +08:00
parent 5d9be1d7e4
commit 520b126ecf
3 changed files with 20 additions and 6 deletions

View File

@@ -11,6 +11,8 @@ import (
type PersonalCustomerClaims struct {
CustomerID uint `json:"customer_id"` // 个人客户 ID
Phone string `json:"phone"` // 手机号
AssetType string `json:"asset_type"` // 登录所用资产类型iot_card / device
AssetID uint `json:"asset_id"` // 登录所用资产 ID
jwt.RegisteredClaims
}
@@ -29,10 +31,12 @@ func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWTManager {
}
// GeneratePersonalCustomerToken 生成个人客户 Token
func (m *JWTManager) GeneratePersonalCustomerToken(customerID uint, phone string) (string, error) {
func (m *JWTManager) GeneratePersonalCustomerToken(customerID uint, phone string, assetType string, assetID uint) (string, error) {
claims := &PersonalCustomerClaims{
CustomerID: customerID,
Phone: phone,
AssetType: assetType,
AssetID: assetID,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(m.tokenDuration)),
IssuedAt: jwt.NewNumericDate(time.Now()),