jwt

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
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 */
)

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

func AllowedAlg(algorithm string) bool

AllowedAlg checks if the algorithm passed has been allowed using a call to AllowAlg().

func HeaderFrom

func HeaderFrom(jwt string) ([]byte, error)

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

func MarshalPublicKey(key *ecdsa.PublicKey) (b64Data string, err error)

MarshalPublicKey marshals an ECDSA public key to a base64 encoded binary representation.

func New

func New(header Header, payload interface{}, privateKey *ecdsa.PrivateKey) (string, 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

func ParsePublicKey(b64Data string, key *ecdsa.PublicKey) error

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

func Payload(jwt string) ([]byte, error)

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

func Verify(jwt string, publicKey *ecdsa.PublicKey, needNewKey bool) (hasMojangKey bool, err error)

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 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL