forked from gofiber/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayload.go
More file actions
33 lines (29 loc) 路 778 Bytes
/
Copy pathpayload.go
File metadata and controls
33 lines (29 loc) 路 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package pasetoware
import (
"github.com/google/uuid"
"github.com/o1egl/paseto"
"time"
)
const (
pasetoTokenAudience = "gofiber.gophers"
pasetoTokenSubject = "user-token"
pasetoTokenField = "data"
)
// NewPayload generates a new paseto.JSONToken and returns it and a error that can be caused by uuid
func NewPayload(userToken string, duration time.Duration) (*paseto.JSONToken, error) {
tokenID, err := uuid.NewRandom()
if err != nil {
return nil, err
}
timeNow := time.Now()
payload := &paseto.JSONToken{
Audience: pasetoTokenAudience,
Jti: tokenID.String(),
Subject: pasetoTokenSubject,
IssuedAt: timeNow,
Expiration: timeNow.Add(duration),
NotBefore: timeNow,
}
payload.Set(pasetoTokenField, userToken)
return payload, nil
}