Skip to content

Commit

Permalink
Mkdocs dev dependency + fix in security
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucino772 authored and lpalmisa committed Mar 24, 2021
1 parent 35ec885 commit 77bf08a
Show file tree
Hide file tree
Showing 7 changed files with 308 additions and 17 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
mkdocs = "*"

[packages]
requests = "*"
Expand Down
282 changes: 277 additions & 5 deletions Pipfile.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions mojang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
>>> profile = mojang.user('Notch')
>>> print(profile.uuid)
'069a79f444e94726a5befca90e38aaf5'
>>> print(profile.skins[0].file.source)
>>> print(profile.skins[0].source)
'http://textures.minecraft.net/texture/292009a4925b58f02c77dadc3ecef07ea4c7472f64e0fdc32ce5522489362680'
>>> ...
Example - Connect with password
>>> import mojang
>>> session = mojang.user('myusername', 'mysecretpassword')
>>> profile = session.profile
>>> ....
>>> session = mojang.connect('Notch', 'notch_secret_password')
>>> print(session.uuid)
'069a79f444e94726a5befca90e38aaf5'
>>> print(profile.skins[0].source)
'http://textures.minecraft.net/texture/292009a4925b58f02c77dadc3ecef07ea4c7472f64e0fdc32ce5522489362680'
>>> ...
"""

from .main import (api_status, connect, get_username, get_uuid, get_uuids,
Expand Down
16 changes: 14 additions & 2 deletions mojang/api/auth/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ def is_user_ip_secure(access_token: str) -> bool:
def get_user_challenges(access_token: str) -> list:
headers = web.get_auth_header(access_token)
data = web.request('get', SECURITY_CHALLENGES, exceptions=(PayloadError, Unauthorized), headers=headers)
return data
challenges = []
if data:
for item in data:
answer_id = item['answer']['id']
question = item['question']['question']
challenges.append((answer_id, question))
return challenges

def verify_user_ip(access_token: str, answers: list) -> bool:
formatted_answers = []
for answer in answers:
formatted_answers.append({
'id': answer[0],
'answer': answer[1]
})
try:
headers = web.get_auth_header(access_token)
web.request('post', SECURITY_CHECK, exceptions=(PayloadError, Unauthorized, IPVerificationError), json=answers, headers=headers)
web.request('post', SECURITY_CHECK, exceptions=(PayloadError, Unauthorized, IPVerificationError), json=formatted_answers, headers=headers)
except IPVerificationError:
return False
else:
Expand Down
7 changes: 4 additions & 3 deletions mojang/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ def name_history(uuid: str) -> list:

data = web.request('get', NAME_HISTORY.format(uuid=uuid))
for item in data:
if 'changedToAt' in item:
item['changedToAt'] = dt.datetime.fromtimestamp(item['changedToAt'])
names.append((item['name'], item.get('changedToAt',None)))
changed_at = None
if 'changedToAt' in item.keys():
changed_at = dt.datetime.fromtimestamp(item['changedToAt'] / 1000)
names.append((item['name'], changed_at))

return names

Expand Down
4 changes: 4 additions & 0 deletions mojang/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ def change_skin(self, path: str, variant='classic'):
def reset_skin(self):
session.reset_user_skin(self.__access_token, self.uuid)
self._fetch_data()


# Remove unused methods from UserProfile
del create
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name='pymojang',
version='0.1',
version='1.0',
author='Lucino772',
author_email='lucapalmi772@gmail.com',
licence='MIT',
Expand Down

0 comments on commit 77bf08a

Please sign in to comment.