auth

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package auth logs players in to servers whose realm issues single-use tickets: jaenster's d2up realm stack and its login service, authd.

The player logs in once, through Discord in their browser. authd gives back a refresh token, which the launcher keeps. Before every box the launcher trades it for a fresh ticket (the account's password for one logon, valid a few minutes) and, with a relay, a tunnel token, and hands them to the game in its environment. A ticket is never cached or reused.

Index

Constants

View Source
const Handoff = "1"

Handoff is the D2UP_HANDOFF contract version the environment follows.

Variables

View Source
var ErrLoggedOut = errors.New("logged out: log in again")

ErrLoggedOut is a refresh token authd no longer accepts: the player has to log in again.

View Source
var ErrTimedOut = errors.New("the login wasn't finished in time")

ErrTimedOut is a login the player didn't finish in the browser in time.

Functions

func Env

func Env(a *spec.Auth, g *Grant) []string

Env is a box's environment for grant g: the d2up handoff contract (d2up's docs/launcher.md, "The handoff contract"). The game reads these once at start and removes them, so nothing it starts inherits the ticket.

func NewNonce

func NewNonce() (string, error)

NewNonce is a login's one-time id, which ties the browser to the poll.

Types

type Client

type Client struct {

	// Poll is the wait between /claim polls.
	Poll time.Duration
	// Timeout is how long a login may take in the browser.
	Timeout time.Duration
	// contains filtered or unexported fields
}

Client talks to one server's authd.

func New

func New(a *spec.Auth, f *fetch.Client) (*Client, error)

New returns a client for the profile's login service, fetching through f, which must allow the profile's hosts.

func (*Client) Claim

func (c *Client) Claim(ctx context.Context, nonce string) (*Grant, error)

Claim asks once whether the login behind nonce has finished. It answers nil, nil while the player is still in the browser.

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context, refresh string) (*Grant, error)

Refresh trades the refresh token for a fresh ticket.

func (*Client) StartURL

func (c *Client) StartURL(nonce string) string

StartURL is the page the player's browser opens to log in.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, nonce string) (*Grant, error)

Wait polls Claim until the login finishes, the timeout passes or ctx ends.

type Grant

type Grant struct {
	Account string `json:"account"`
	Ticket  string `json:"ticket"`
	// Refresh is only in the answer to a new login.
	Refresh string `json:"refresh,omitempty"`
	Name    string `json:"name,omitempty"`
	// Tunnel is the relay token, when the server runs one.
	Tunnel string `json:"tunnel,omitempty"`
}

Grant is what authd answers to a login or a refresh.

Jump to

Keyboard shortcuts

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