Class: Lapis::Yggdrasil::Messaging::AuthenticationRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/lapis/yggdrasil/messaging/authentication_request.rb

Overview

Message sent to attempt to authenticate.

Instance Method Summary collapse

Constructor Details

#initialize(username, password, agent, client_token = nil) ⇒ AuthenticationRequest

Creates a new authentication request.

Parameters:

  • username (String)

    Minecraft username or Mojang account email address.

  • password (String)

    Password for the user.

  • agent (Agent)

    Game information being requested.

  • client_token (Uuid, nil) (defaults to: nil)

    ID for the client instance. Provide nil to have the authentication server provide one.



18
19
20
21
22
23
# File 'lib/lapis/yggdrasil/messaging/authentication_request.rb', line 18

def initialize(username, password, agent, client_token = nil)
  @username     = username.dup.freeze
  @password     = password.dup.freeze
  @agent        = agent
  @client_token = client_token
end

Instance Method Details

#endpointString

Path on the server that handles the request.

Returns:

  • (String)

    Path to handler.



27
28
29
# File 'lib/lapis/yggdrasil/messaging/authentication_request.rb', line 27

def endpoint
  '/authenticate'
end

#to_jsonString

Generates a JSON string that can be sent to an authentication server.

Returns:

  • (String)

    JSON string.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lapis/yggdrasil/messaging/authentication_request.rb', line 33

def to_json
  hash = {
      :agent => {
          :name    => @agent.name,
          :version => @agent.version
      },
      :username => @username,
      :password => @password
  }
  hash[:clientToken] = @client_token.to_s(false) if @client_token
  hash.to_json
end