yggdrasil

package
v1.19.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 6 Imported by: 13

Documentation

Overview

Package yggdrasil implement Yggdrasil protocol.

Minecraft 1.6 introduced a new authentication scheme called Yggdrasil which completely replaces the previous authentication system. Mojang's other game, Scrolls, uses this method of authentication as well. Mojang has said that this authentication system should be used by everyone for custom logins, but credentials should never be collected from users. ----- https://wiki.vg

Example
var user, password string // set your proof

// Sign in
resp, err := Authenticate(user, password)
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}
id, name := resp.SelectedProfile()
fmt.Println("user:", name)
fmt.Println("uuid:", id)
fmt.Println("astk:", resp.AccessToken())

// Refresh access token
if err := resp.Refresh(nil); err != nil {
	fmt.Println(err)
	os.Exit(1)
}

id, name = resp.SelectedProfile()
fmt.Println("user:", name)
fmt.Println("uuid:", id)
fmt.Println("astk:", resp.AccessToken())

// Check access token
ok, err := resp.Validate()
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}
fmt.Println("at status: ", ok)

// Invalidate access token
err = resp.Invalidate()
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}

// Check access token
ok, err = resp.Validate()
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}
fmt.Println("at status: ", ok)

// Sign out
err = SignOut(user, password)
if err != nil {
	fmt.Println(err)
	os.Exit(1)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var AuthURL = "https://authserver.mojang.com"

Functions

func SignOut

func SignOut(user, password string) error

SignOut invalidates accessTokens using an account's username and password.

Types

type Access

type Access struct {
	// contains filtered or unexported fields
}

func Authenticate

func Authenticate(user, password string) (*Access, error)

Authenticate authenticates a user using their password.

Example
resp, err := Authenticate("", "")
if err != nil {
	panic(err)
}

fmt.Println(resp.SelectedProfile())
fmt.Println(resp.AccessToken())
Output:

func (*Access) AccessToken

func (a *Access) AccessToken() string

func (*Access) AvailableProfiles

func (a *Access) AvailableProfiles() []Profile

func (*Access) GetTokens

func (a *Access) GetTokens() Tokens

func (*Access) Invalidate

func (a *Access) Invalidate() error

Invalidate invalidates accessTokens using a client/access token pair.

func (*Access) Refresh

func (a *Access) Refresh(profile *Profile) error

Refresh refreshes a valid accessToken.

It can be used to keep a user logged in between gaming sessions and is preferred over storing the user's password in a file

func (*Access) SelectedProfile

func (a *Access) SelectedProfile() (ID, Name string)

func (*Access) SetTokens

func (a *Access) SetTokens(tokens Tokens)

func (*Access) Validate

func (a *Access) Validate() (bool, error)

Validate checks if an accessToken is usable for authentication with a Minecraft server.

type Error

type Error struct {
	Err    string `json:"error"`
	ErrMsg string `json:"errorMessage"`
	Cause  string `json:"cause"`
}

func (Error) Error

func (e Error) Error() string

type Profile

type Profile struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

type Tokens

type Tokens struct {
	AccessToken string `json:"accessToken"`
	ClientToken string `json:"clientToken"`
}

Tokens store AccessToken and ClientToken

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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