devicemngmt/auth_token.go

18 lines
423 B
Go
Raw Normal View History

2021-11-05 07:18:59 +00:00
package devicemngmt
import (
"time"
"github.com/dgrijalva/jwt-go"
"go.mongodb.org/mongo-driver/bson/primitive"
)
func (s Service) generateAuthToken(userID primitive.ObjectID) string {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"_id": userID,
"exp": now().Add(time.Second * 15552000).Unix(), // 6 months
})
tokenString, _ := token.SignedString([]byte(s.AuthSecret))
return tokenString
}