internal

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthPolicy = SignaturePolicy{
	Version: 1,
}

AuthPolicy is the hardcoded signature policy used for authentication/authorization requests for Xbox Live, including XASD, XAST, XASU, and XSTS.

Functions

func ProofKey

func ProofKey(key *ecdsa.PrivateKey) jose.JSONWebKey

func ValidToken added in v2.0.2

func ValidToken(token string, notAfter time.Time) bool

ValidToken reports whether token is non-empty and expires after the refresh margin used for Xbox authentication tokens.

Types

type SignaturePolicy added in v2.0.2

type SignaturePolicy struct {
	// Version is the version for the SignaturePolicy. It is typically 1
	// for most SignaturePolicy listed in a TitleData.
	Version uint32
	// SupportedAlgorithms is a list of algorithms supported for signing
	// the request. The meanings or semantics of this field is currently
	// unknown. Known values are 'XBL' and 'DPoP'.
	SupportedAlgorithms []string
	// MaxBodyBytes is the maximum length of request body that can be signed
	// in a single request when using this policy. If 0, the whole request
	// body will be signed.
	MaxBodyBytes int
	// ExtraHeaders specifies additional headers that should be signed.
	// It is typically empty, but rarely used in some titles.
	// Note that the 'Authorization' header of the request is always
	// signed.
	ExtraHeaders []string
}

SignaturePolicy encapsulates a policy for signing requests in NSAL.

func (SignaturePolicy) Generate added in v2.0.2

func (policy SignaturePolicy) Generate(request *http.Request, body []byte, key *ecdsa.PrivateKey, timestamp time.Time) ([]byte, error)

Generate computes a signature for the provided HTTP request and returns it as raw bytes, which callers will typically encode using base64.StdEncoding. For most use cases, prefer SignaturePolicy.Sign, which computes the signature and sets the 'Signature' header directly.

The key must match the proof key used in the authentication request, and the timestamp should be as close to the server time as possible to avoid rejection.

Generate returns an error if key is nil, key is not P-256, or if ecdsa.Sign fails.

func (SignaturePolicy) Sign added in v2.0.2

func (policy SignaturePolicy) Sign(request *http.Request, body []byte, key *ecdsa.PrivateKey, timestamp time.Time) error

Sign signs the request and sets the 'Signature' header. The provided request body will be used for computing an SHA-256 hash. The ECDSA private key will be used to sign the request, which must be same from the ProofKey field of authentication requests. The timestamp is included in the signature data and must be close to the server time as possible.

type Token

type Token[C any] struct {
	// IssueInstant is the time when the Token is created.
	IssueInstant time.Time
	// NotAfter is the expiration time of the Token.
	NotAfter time.Time
	// Token is the JWT for the Token.
	Token string
	// DisplayClaims contains additional data claimed from the issuer of
	// the Token. It generally contains fields about representing a user,
	// device, or title.
	DisplayClaims C
}

Token represents the basic structure of the Token issued by various Xbox Authentication Services (XAS). The C generic type indicates the struct type of the DisplayClaims field.

func (*Token[C]) Valid

func (t *Token[C]) Valid() bool

Valid returns whether the Token is a valid token.

type TokenRequest

type TokenRequest[P any] struct {
	// RelyingParty is a URI representing the relying-party, which the token should be
	// authorized for. It is typically 'http' or 'rp' URI.
	RelyingParty string

	// TokenType indicates that type of the token.
	// It is typically 'JWT' for most tokens.
	TokenType string

	// Properties is the properties specific to the token.
	// It may contain the 'ProofKey' field, which is a JWK object
	// representing the key used for the device token.
	Properties P
}

TokenRequest represents the wire structure of the request used for requesting tokens in Xbox Authentication Services. Make sure to specify the P generic type to whatever you want to specify in the Properties field.

func (TokenRequest[P]) Do

func (r TokenRequest[P]) Do(ctx context.Context, config xal.Config, reqURL string, proofKey *ecdsa.PrivateKey, respBody any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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