Skip to content

Commit

Permalink
Documentation for mojang.api.auth.yggdrasil
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucino772 committed Mar 24, 2021
1 parent a0be3e6 commit 609ce40
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ verify_ssl = true

[dev-packages]
mkdocs = "*"
mkdocs-material = "*"
mkdocstrings = "*"

[packages]
requests = "*"
Expand Down
74 changes: 73 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions docs/PyMojang/yggdrasil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Mojang Authentication with Yggdrasil
===

::: mojang.api.auth.yggdrasil
handler: python
selection:
members:
- authenticate_user
- refresh_token
- validate_token
- signout_user
- invalidate_token
rendering:
show_root_heading: true
show_source: true
21 changes: 13 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ site_name: PyMojang
repo_url: https://github.com/Lucino772/pymojang
site_author: Lucino772

theme: readthedocs
theme:
name: "material"

markdown_extensions:
- admonition

plugins:
- search
- mkdocstrings

extra_css:
- css/extra.css

Expand All @@ -19,10 +24,10 @@ nav:
- 'Profile and Authentication': 'advanced.md'

- PyMojang:
- 'mojang.api.auth.yggdrasil': '/PyMojang/yggdrasil.md'
- 'mojang.api.auth.security': '/PyMojang/secuity.md'
- 'mojang.api.base': '/PyMojang/base.md'
- 'mojang.api.session': '/PyMojang/session.md'
- 'mojang.profile.UserProfile': '/PyMojang/UserProfile.md'
- 'mojang.session.UserSession': '/PyMojang/UserSession.md'
- 'Exceptions': '/PyMojang/exceptions.md'
- 'mojang.api.auth.yggdrasil': 'PyMojang/yggdrasil.md'
- 'mojang.api.auth.security': 'PyMojang/secuity.md'
- 'mojang.api.base': 'PyMojang/base.md'
- 'mojang.api.session': 'PyMojang/session.md'
- 'mojang.profile.UserProfile': 'PyMojang/UserProfile.md'
- 'mojang.session.UserSession': 'PyMojang/UserSession.md'
- 'Exceptions': 'PyMojang/exceptions.md'
61 changes: 60 additions & 1 deletion mojang/api/auth/yggdrasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@


def authenticate_user(username: str, password: str, client_token=None) -> dict:
"""Authenticate user with name and password
Args:
username (str): The username or email if account is not legacy
password (str): The user password
client_token (str, optional): The client token to use in the authentication (default to None)
Returns:
A dict with thet following keys : `access_token`, `client_token`, `uuid`, `name`,
`legacy` and `demo`
Raises:
CredentialsError: If username and password are invalid
PayloadError: If credentials are not formated correctly
"""
payload = {
'username': username,
'password': password,
Expand All @@ -29,7 +44,21 @@ def authenticate_user(username: str, password: str, client_token=None) -> dict:
'demo': not data['selectedProfile'].get('paid', True)
}

def refresh_token(access_token: str, client_token: str):
def refresh_token(access_token: str, client_token: str) -> dict:
"""Refresh an invalid access token
Args:
access_token (str): The access token to refresh
clien_token (str): The client token used to generate the access token
Returns:
A dict with the following keys: `access_token`, `client_token`, `uuid`, `name`,
`legacy` and `demo`
Raises:
TokenError: If client token is not the one used to generate the access token
PayloadError: If the tokens are not formated correctly
"""
payload = {
'accessToken': access_token,
'clientToken': client_token
Expand All @@ -47,6 +76,16 @@ def refresh_token(access_token: str, client_token: str):
}

def validate_token(access_token: str, client_token: str):
"""Validate an access token
Args:
access_token (str): The access token to validate
clien_token (str): The client token used to generate the access token
Raises:
TokenError: If client token is not the one used to generate the access token
PayloadError: If the tokens are not formated correctly
"""
payload = {
'accessToken': access_token,
'clientToken': client_token
Expand All @@ -55,6 +94,16 @@ def validate_token(access_token: str, client_token: str):
web.request('post', VALIDATE, exceptions=(PayloadError, TokenError), json=payload)

def signout_user(username: str, password: str):
"""Signout user with name and password
Args:
username (str): The username or email if account is not legacy
password (str): The user password
Raises:
CredentialsError: If username and password are invalid
PayloadError: If credentials are not formated correctly
"""
payload = {
'username': ctx.username,
'password': ctx.password
Expand All @@ -63,6 +112,16 @@ def signout_user(username: str, password: str):
web.request('post', SIGNOUT, exceptions=(PayloadError, CredentialsError), json=payload)

def invalidate_token(access_token: str, client_token: str):
"""Invalidate an access token
Args:
access_token (str): The access token to invalidate
clien_token (str): The client token used to generate the access token
Raises:
TokenError: If client token is not the one used to generate the access token
PayloadError: If the tokens are not formated correctly
"""
payload = {
'accessToken': access_token,
'clientToken': client_token
Expand Down

0 comments on commit 609ce40

Please sign in to comment.