auth

package
v1.39.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 22 Imported by: 36

Documentation

Overview

Package auth implements authentication to Microsoft Live Connect accounts, XBOX Live accounts and ultimately Minecraft accounts associated with them. Microsoft Live Connect auth is performed using device auth.

The auth package provides token sources for Microsoft Live Connect auth with an oauth2-style interface, with token sources that may be plugged into services directly.

Index

Constants

This section is empty.

Variables

View Source
var TokenSource oauth2.TokenSource = &tokenSource{w: os.Stdout}

TokenSource holds an oauth2.TokenSource which uses device auth to get a code. The user authenticates using a code. TokenSource prints the authentication code and URL to os.Stdout. To use a different io.Writer, use WriterTokenSource. TokenSource automatically refreshes tokens.

Functions

func RefreshTokenSource

func RefreshTokenSource(t *oauth2.Token) oauth2.TokenSource

RefreshTokenSource returns a new oauth2.TokenSource using the oauth2.Token passed that automatically refreshes the token everytime it expires. Note that this function must be used over oauth2.ReuseTokenSource due to that function not refreshing with the correct scopes.

func RefreshTokenSourceWriter

func RefreshTokenSourceWriter(t *oauth2.Token, w io.Writer) oauth2.TokenSource

RefreshTokenSourceWriter returns a new oauth2.TokenSource using the oauth2.Token passed that automatically refreshes the token everytime it expires. It requests from io.Writer if the oauth2.Token is invalid. Note that this function must be used over oauth2.ReuseTokenSource due to that function not refreshing with the correct scopes.

func RequestLiveToken

func RequestLiveToken() (*oauth2.Token, error)

RequestLiveToken does a login request for Microsoft Live Connect using device auth. A login URL will be printed to the stdout with a user code which the user must use to submit. RequestLiveToken is the equivalent of RequestLiveTokenWriter(os.Stdout).

func RequestLiveTokenWriter

func RequestLiveTokenWriter(w io.Writer) (*oauth2.Token, error)

RequestLiveTokenWriter does a login request for Microsoft Live Connect using device auth. A login URL will be printed to the io.Writer passed with a user code which the user must use to submit. Once fully authenticated, an oauth2 token is returned which may be used to login to XBOX Live.

func RequestMinecraftChain

func RequestMinecraftChain(ctx context.Context, token *XBLToken, key *ecdsa.PrivateKey) (string, error)

RequestMinecraftChain requests a fully processed Minecraft JWT chain using the XSTS token passed, and the ECDSA private key of the client. This key will later be used to initialise encryption, and must be saved for when packets need to be decrypted/encrypted.

func WriterTokenSource

func WriterTokenSource(w io.Writer) oauth2.TokenSource

WriterTokenSource returns a new oauth2.TokenSource which, like TokenSource, uses device auth to get a code. Unlike TokenSource, WriterTokenSource allows passing an io.Writer to which information on the auth URL and code are printed. WriterTokenSource automatically refreshes tokens.

Types

type XBLToken

type XBLToken struct {
	AuthorizationToken struct {
		DisplayClaims struct {
			UserInfo []struct {
				GamerTag string `json:"gtg"`
				XUID     string `json:"xid"`
				UserHash string `json:"uhs"`
			} `json:"xui"`
		}
		Token string
	}
}

XBLToken holds info on the authorization token used for authenticating with XBOX Live.

func RequestXBLToken

func RequestXBLToken(ctx context.Context, liveToken *oauth2.Token, relyingParty string) (*XBLToken, error)

RequestXBLToken requests an XBOX Live auth token using the passed Live token pair.

func (XBLToken) SetAuthHeader

func (t XBLToken) SetAuthHeader(r *http.Request)

SetAuthHeader returns a string that may be used for the 'Authorization' header used for Minecraft related endpoints that need an XBOX Live authenticated caller.

Jump to

Keyboard shortcuts

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