hub apis
This commit is contained in:
@@ -24,6 +24,7 @@ type Claims struct {
|
||||
RoleID int `json:"roleid"`
|
||||
TenantID int `json:"tenantid"`
|
||||
ConfigID int `json:"configid,omitempty"`
|
||||
HubID int `json:"hubid,omitempty"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
||||
@@ -45,6 +46,26 @@ func GenerateToken(userID int, email string, roleID int, tenantID int, configID
|
||||
return token.SignedString([]byte(secret))
|
||||
}
|
||||
|
||||
// GenerateHubStaffToken issues a JWT for hub console staff (role 6), carrying
|
||||
// HubID instead of TenantID/ConfigID so hub handlers can scope queries via
|
||||
// c.Locals("hubid") without colliding with the Miler role (5).
|
||||
func GenerateHubStaffToken(userID int, email string, hubID int, secret string) (string, error) {
|
||||
expirationTime := time.Now().Add(24 * time.Hour)
|
||||
claims := &Claims{
|
||||
UserID: userID,
|
||||
Email: email,
|
||||
RoleID: 6,
|
||||
HubID: hubID,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(expirationTime),
|
||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||
},
|
||||
}
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
return token.SignedString([]byte(secret))
|
||||
}
|
||||
|
||||
func ParseToken(tokenString string, secret string) (*Claims, error) {
|
||||
token, err := jwt.ParseWithClaims(tokenString, &Claims{}, func(token *jwt.Token) (interface{}, error) {
|
||||
return []byte(secret), nil
|
||||
|
||||
Reference in New Issue
Block a user