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:
@@ -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()),
|
||||
|
||||
Reference in New Issue
Block a user