2020-04-04 06:51:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gbrlsnchs/jwt/v3"
|
|
|
|
"github.com/pterodactyl/wings/config"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2020-04-06 01:00:33 +00:00
|
|
|
var alg *jwt.HMACSHA
|
|
|
|
|
2020-04-04 06:51:35 +00:00
|
|
|
// ArchiveTokenPayload represents an Archive Token Payload.
|
|
|
|
type ArchiveTokenPayload struct {
|
|
|
|
jwt.Payload
|
|
|
|
}
|
|
|
|
|
|
|
|
func ParseArchiveJWT(token []byte) (*ArchiveTokenPayload, error) {
|
|
|
|
var payload ArchiveTokenPayload
|
|
|
|
if alg == nil {
|
|
|
|
alg = jwt.NewHS256([]byte(config.Get().AuthenticationToken))
|
|
|
|
}
|
|
|
|
|
|
|
|
now := time.Now()
|
|
|
|
verifyOptions := jwt.ValidatePayload(
|
|
|
|
&payload.Payload,
|
|
|
|
jwt.ExpirationTimeValidator(now),
|
|
|
|
)
|
|
|
|
|
|
|
|
_, err := jwt.Verify(token, alg, &payload, verifyOptions)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &payload, nil
|
|
|
|
}
|