mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-30 18:25:41 +01:00
Remove sensitive data from JWT and add expiry
This commit is contained in:
committed by
Roman Useinov
parent
95512462f6
commit
b1dd3012fd
@@ -1,25 +1,28 @@
|
||||
package tokens
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/bumi/lndhub.go/db/models"
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
)
|
||||
|
||||
type jwtCustomClaims struct {
|
||||
ID int64 `json:"id"`
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
ID int64 `json:"id"`
|
||||
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
// GenerateAccessToken : Generate Access Token
|
||||
func GenerateAccessToken(u *models.User) (string, error) {
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwtCustomClaims{
|
||||
ID: u.ID,
|
||||
Email: u.Email.String,
|
||||
Login: u.Login,
|
||||
})
|
||||
claims := &jwtCustomClaims{
|
||||
u.ID,
|
||||
jwt.StandardClaims{
|
||||
// one week expiration
|
||||
ExpiresAt: time.Now().Add(time.Hour * 27 * 7).Unix(),
|
||||
},
|
||||
}
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
|
||||
|
||||
t, err := token.SignedString([]byte("secret"))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user