Documentation ¶
Index ¶
- Constants
- func AllowAlg(alg ...string)
- func AllowedAlg(algorithm string) bool
- func HeaderFrom(jwt []byte) ([]byte, error)
- func MarshalPublicKey(key *ecdsa.PublicKey) string
- func New(header Header, payload interface{}, privateKey *ecdsa.PrivateKey) ([]byte, error)
- func ParsePublicKey(b64Data string, key *ecdsa.PublicKey) error
- func Payload(jwt []byte) ([]byte, error)
- func Verify(jwt []byte, publicKey *ecdsa.PublicKey, needNewKey bool) (hasMojangKey bool, err error)
- type Header
Constants ¶
const ( // MojangPublicKey is the public key used by Mojang to sign one of the claims in a chain, indicating that // the player was logged into XBOX Live. MojangPublicKey = `` /* 160-byte string literal not displayed */ )
noinspection SpellCheckingInspection
Variables ¶
This section is empty.
Functions ¶
func AllowAlg ¶
func AllowAlg(alg ...string)
AllowAlg adds a variadic amount of algorithms which JWT headers may have. Any algorithm found in a JWT header will be assumed as an error and returned during verification.
func AllowedAlg ¶
AllowedAlg checks if the algorithm passed has been allowed using a call to AllowAlg().
func HeaderFrom ¶
Header parses the JWT passed and returns the base64 decoded header section of the claim. The JSON data returned is not guaranteed to be valid JSON.
func MarshalPublicKey ¶
MarshalPublicKey marshals an ECDSA public key to a base64 encoded binary representation.
func New ¶
func New(header Header, payload interface{}, privateKey *ecdsa.PrivateKey) ([]byte, error)
New produces an encoded JWT from the header and payload passed. The signature of the JWT is created using the private key passed.
func ParsePublicKey ¶
ParsePublicKey parses a public key from the base64 encoded public key data passed and sets it to the public key pointer. If parsing failed or if the public key was not of the type ECDSA, an error is returned.
func Payload ¶
Payload parses the JWT passed and returns the base64 decoded payload section of the claim. The JSON data returned is not guaranteed to be valid JSON.
func Verify ¶
Verify verifies a single raw JWT string, which exists out of a header, payload and a signature. The JWT is first checked to be valid, after which its signature is verified. The publicKey passed is used to verify the signature of the claim. If a zero public key is passed (meaning, not a nil pointer, but an empty *ecdsa.PublicKey{}), the key is retrieved from the x5u of the header. The public key passed will be updated for the identityPublicKey found in the claim.
Types ¶
type Header ¶
type Header struct { // Algorithm is the algorithm used for the signature in the signature section of the claim. Any algorithm // that isn't allowed using AllowAlg will result in an error instead. Algorithm string `json:"alg"` X5U string `json:"x5u"` }
Header holds the header information of a JWT claim.