Class: Lapis::Yggdrasil::AuthenticationClient
- Defined in:
- lib/lapis/yggdrasil/authentication_client.rb
Overview
Provides interaction with an authentication server.
Constant Summary collapse
- OFFICIAL_AUTHENTICATION_URL =
URL of the official Mojang authentication server.
'https://authserver.mojang.com'
Class Method Summary collapse
-
.official ⇒ AuthenticationClient
Singleton for accessing the official Mojang authentication server.
Instance Method Summary collapse
-
#authenticate(username, password, client_token = nil, agent = Agent::DEFAULT_AGENT) ⇒ Session
Create a new session by authenticating with the server.
-
#initialize(url) ⇒ AuthenticationClient
constructor
Creates a new interface to an authentication server.
-
#invalidate(session) ⇒ void
Marks a previously used session as not valid.
-
#refresh(session, profile = nil) ⇒ SessionInfo
Refresh a session that was previously used.
-
#signout(username, password) ⇒ void
Invalidates a session by using credentials instead of authentication tokens.
-
#validate(session) ⇒ true, false
Checks that a previously used session is still valid.
Constructor Details
#initialize(url) ⇒ AuthenticationClient
Creates a new interface to an authentication server.
19 20 21 22 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 19 def initialize(url) super(url) @factory = Messaging::ResponseFactory.new end |
Class Method Details
.official ⇒ AuthenticationClient
Singleton for accessing the official Mojang authentication server.
26 27 28 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 26 def self.official @official ||= new(OFFICIAL_AUTHENTICATION_URL) end |
Instance Method Details
#authenticate(username, password, client_token = nil, agent = Agent::DEFAULT_AGENT) ⇒ Session
Create a new session by authenticating with the server.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 38 def authenticate(username, password, client_token = nil, agent = Agent::DEFAULT_AGENT) request = Messaging::AuthenticationRequest.new(username, password, agent, client_token) response = send_request(request) = @factory.parse_authentication_response(response) if .ok? info = SessionInfo.new(.client_token, .access_token, .selected_profile) Session.new(info, self) else fail .to_error end end |
#invalidate(session) ⇒ void
This method returns an undefined value.
Marks a previously used session as not valid.
96 97 98 99 100 101 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 96 def invalidate(session) request = Messaging::InvalidateRequest.new(session.client_token, session.access_token) response = send_request(request) = @factory.parse_invalidate_response(response) fail .to_error unless .ok? end |
#refresh(session, profile = nil) ⇒ SessionInfo
Setting profile
to anything other than nil
will result in an error. In the current version of Yggdrasil, switching profiles is not supported.
Refresh a session that was previously used.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 58 def refresh(session, profile = nil) request = Messaging::RefreshRequest.new(session.client_token, session.access_token, profile) response = send_request(request) = @factory.parse_refresh_response(response) if .ok? SessionInfo.new(.client_token, .access_token, .profile) else fail .to_error end end |
#signout(username, password) ⇒ void
This method returns an undefined value.
Invalidates a session by using credentials instead of authentication tokens.
85 86 87 88 89 90 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 85 def signout(username, password) request = Messaging::SignoutRequest.new(username, password) response = send_request(request) = @factory.parse_signout_response(response) fail .to_error unless .ok? end |
#validate(session) ⇒ true, false
Checks that a previously used session is still valid.
73 74 75 76 77 78 |
# File 'lib/lapis/yggdrasil/authentication_client.rb', line 73 def validate(session) request = Messaging::ValidateRequest.new(session.client_token, session.access_token) response = send_request(request) = @factory.parse_validate_response(response) .ok? end |