2020-04-06 01:44:16 +00:00
|
|
|
package tokens
|
|
|
|
|
|
|
|
import (
|
2021-08-02 21:07:00 +00:00
|
|
|
"time"
|
|
|
|
|
2020-04-06 01:44:16 +00:00
|
|
|
"github.com/gbrlsnchs/jwt/v3"
|
2021-08-02 21:07:00 +00:00
|
|
|
|
2020-04-06 01:44:16 +00:00
|
|
|
"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()),
|
|
|
|
)
|
|
|
|
|
2020-04-12 00:26:17 +00:00
|
|
|
_, err := jwt.Verify(token, config.GetJwtAlgorithm(), &data, verifyOptions)
|
2020-04-06 01:44:16 +00:00
|
|
|
|
|
|
|
return err
|
2020-04-06 01:56:54 +00:00
|
|
|
}
|