wings/router/tokens/parser.go
Matthew Penner 3c54c1f840 break everything
- upgrade dependencies
- run gofmt and goimports to organize code
- fix typos
- other small tweaks
2021-08-02 15:07:00 -06:00

30 lines
731 B
Go

package tokens
import (
"time"
"github.com/gbrlsnchs/jwt/v3"
"github.com/pterodactyl/wings/config"
)
type TokenData interface {
GetPayload() *jwt.Payload
}
// Validates the provided JWT against the known secret for the Daemon and returns the
// parsed data. This function DOES NOT validate that the token is valid for the connected
// server, nor does it ensure that the user providing the token is able to actually do things.
//
// This simply returns a parsed token.
func ParseToken(token []byte, data TokenData) error {
verifyOptions := jwt.ValidatePayload(
data.GetPayload(),
jwt.ExpirationTimeValidator(time.Now()),
)
_, err := jwt.Verify(token, config.GetJwtAlgorithm(), &data, verifyOptions)
return err
}