Finished up authentication.py, I hope. Still needs tests and documentation
This commit is contained in:
1 parent
5242c68240
commit
c1e7960165
1 file changed
+29
-9
@@ -73,9 +73,19 @@ class AuthenticationToken(object):
|
|||||||
Attribute which is ``True`` when the token is authenticated and
|
Attribute which is ``True`` when the token is authenticated and
|
||||||
``False`` when it isn't.
|
``False`` when it isn't.
|
||||||
"""
|
"""
|
||||||
# TODO
|
if not self.username:
|
||||||
return True
|
return False
|
||||||
|
|
||||||
|
if not self.access_token:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.client_token:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self.profile:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def authenticate(self, username, password):
|
def authenticate(self, username, password):
|
||||||
"""
|
"""
|
||||||
@@ -183,7 +193,8 @@ class AuthenticationToken(object):
|
|||||||
`username` and `password`.
|
`username` and `password`.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
TODO
|
username - ``str`` containing the username
|
||||||
|
password - ``str`` containing the password
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Returns `True` if sign out was successful.
|
Returns `True` if sign out was successful.
|
||||||
@@ -204,12 +215,19 @@ class AuthenticationToken(object):
|
|||||||
the `AuthenticationToken`.
|
the `AuthenticationToken`.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
TODO
|
``True`` if tokens were successfully invalidated.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
TODO
|
:class:`minecraft.exceptions.YggdrasilError`
|
||||||
"""
|
"""
|
||||||
pass
|
req = _make_request(AUTHSERVER, "invalidate",
|
||||||
|
{"accessToken": self.access_token,
|
||||||
|
"clientToken": self.client_token})
|
||||||
|
|
||||||
|
if status_code == requests.codes.ok and not req.text:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
raise YggdrasilError("Failed to invalidate tokens.")
|
||||||
|
|
||||||
def join(self, server_id):
|
def join(self, server_id):
|
||||||
"""
|
"""
|
||||||
@@ -226,6 +244,10 @@ class AuthenticationToken(object):
|
|||||||
:class:`minecraft.exceptions.YggdrasilError`
|
:class:`minecraft.exceptions.YggdrasilError`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
if not self.authenticated:
|
||||||
|
err = "AuthenticationToken hasn't been authenticated yet!"
|
||||||
|
raise YggdrasilError(err)
|
||||||
|
|
||||||
req = _make_request(SESSIONSERVER, "join",
|
req = _make_request(SESSIONSERVER, "join",
|
||||||
{"accessToken": self.access_token,
|
{"accessToken": self.access_token,
|
||||||
"selectedProfile": self.profile.to_dict(),
|
"selectedProfile": self.profile.to_dict(),
|
||||||
@@ -234,9 +256,7 @@ class AuthenticationToken(object):
|
|||||||
if req.status_code == requests.codes.ok:
|
if req.status_code == requests.codes.ok:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return req
|
raise YggdrasilError("Failed to join game.")
|
||||||
err = "Failed to join game. Status code: {}"
|
|
||||||
raise YggdrasilError(err.format(str(req.status_code)))
|
|
||||||
|
|
||||||
|
|
||||||
def _make_request(server, endpoint, data):
|
def _make_request(server, endpoint, data):
|
||||||
|
|||||||
Reference in new issue
Block a user