mojang

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package mojang allows to login to a mojang account in order to start Minecraft

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotFound gets returned when a 404 occurred
	ErrorNotFound = errors.New("resource not found")
	// ErrorBadRequest gets returned when a 400 occurred
	ErrorBadRequest = errors.New("bad Request")
)

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	AccessToken     string   `json:"accessToken"`
	ClientToken     string   `json:"clientToken"`
	SelectedProfile *Profile `json:"selectedProfile"`
}

AuthResponse is the response returned by a succefully mojang login

type Client

type Client struct {
	// HTTP is the internal http client
	HTTP *http.Client
}

Client contains credentials and methods to talk to the mojang api

func New

func New() *Client

New returns a new MojangAPI instance

func NewWithClient

func NewWithClient(client *http.Client) *Client

NewWithClient returns a new MojangAPI instance using a custom http client supplied as a first parameter

func (*Client) DecorateRequest

func (m *Client) DecorateRequest(req *http.Request)

DecorateRequest decorates a provided http request with the User-Agent header and a auth header if set

func (*Client) Login

func (m *Client) Login(username string, password string) (*AuthResponse, error)

Login is a convenient method that uses username/password credentials to fetch a token from Mojangs Authentication Server. It then uses (only) that token to login to minepkg

func (*Client) MojangEnsureToken

func (m *Client) MojangEnsureToken(accessToken string, clientToken string) (*AuthResponse, error)

MojangEnsureToken checks if the token need to be refreshed and does so it required. it returns a valid token

func (*Client) MojangRefreshToken

func (m *Client) MojangRefreshToken(accessToken string, clientToken string) (*AuthResponse, error)

MojangRefreshToken refreshed the given token

type Profile

type Profile struct {
	Agent         string `json:"agent"`
	ID            string `json:"id"`
	Name          string `json:"name"`
	UserID        string `json:"userId"`
	TokenID       string `json:"tokenId"`
	CreatedAt     int    `json:"createdAt"`
	LegacyProfile bool   `json:"legacyProfile"`
	Suspended     bool   `json:"suspended"`
	Paid          bool   `json:"paid"`
	Migrated      bool   `json:"migrated"`
}

Profile is a profile that potentially can be used to launch minecraft

Jump to

Keyboard shortcuts

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