Documentation
¶
Overview ¶
Package auth provides a way to authenticate joining online mode players with Mojang's session server.
Index ¶
Constants ¶
const DefaultPrivateKeyBits = 1024
DefaultPrivateKeyBits is the default bit size of a generated private key.
It matches what vanilla Minecraft servers and other proxies (BungeeCord, Velocity) use for the login handshake, so it stays the default for compatibility. Operators can raise it with Options.PrivateKeyBits.
Variables ¶
This section is empty.
Functions ¶
func DefaultHasJoinedURL ¶ added in v0.12.0
DefaultHasJoinedURL returns the default hasJoined URL for the given serverID and username. The userIP is optional.
Types ¶
type Authenticator ¶
type Authenticator interface {
// PublicKey returns the public key encoded in ASN.1 DER form.
PublicKey() []byte
// Verify verifies the "verify token" sent by joining client.
Verify(encryptedVerifyToken, actualVerifyToken []byte) (equal bool, err error)
DecryptSharedSecret(encrypted []byte) (decrypted []byte, err error)
// GenerateServerID Generate server id to be used with AuthenticateJoin.
GenerateServerID(decryptedSharedSecret []byte) (serverID string, err error)
// AuthenticateJoin Authenticates a joining user. The ip is optional.
AuthenticateJoin(ctx context.Context, serverID, username, ip string) (Response, error)
// SetHasJoinedURLFn sets the HasJoinedURLFn.
// If not set, DefaultHasJoinedURL is used.
SetHasJoinedURLFn(fn HasJoinedURLFn)
}
Authenticator is a Mojang user authenticator.
type HasJoinedURLFn ¶ added in v0.12.0
HasJoinedURLFn returns the url to authenticate a joining online mode user. Note that userIP is optional. See DefaultHasJoinedURL for the default implementation.
func CustomHasJoinedURL ¶ added in v0.34.0
func CustomHasJoinedURL(baseURL *url.URL) HasJoinedURLFn
CustomHasJoinedURL returns a HasJoinedURLFn that uses the given baseURL instead of the default official Mojang API.
type Options ¶
type Options struct {
// This setting allows to an authentication url other
// than the official "hasJoined" Mojang API endpoint.
// The returned url is used to authenticate a joining
// online mode user.
// If not set, DefaultHasJoinedURL is used.
HasJoinedURLFn HasJoinedURLFn
// The servers private key.
// If none is set, a new one will be generated.
PrivateKey *rsa.PrivateKey
// PrivateKey is not set,
// the bit size of a generated private key.
// If unset or <= 0, DefaultPrivateKeyBits is used.
// Note that rsa.GenerateKey rejects sizes below 1024 bits.
PrivateKeyBits int
// The http client to query the Mojang API.
// If none is set, a new one is created.
Client *http.Client
}
Options to create a new Authenticator.