microsoft_account
microsoft_account contains functions for login with a Microsoft Account. Before using this module you need to create a Azure application. Many thanks to wiki.vg for it’s documentation of the login process. You may want to read the Microsoft Login tutorial before using this module. For a list of all types see microsoft_types.
- get_login_url(client_id: str, redirect_uri: str) str
Generate a login url.For a more secure alternative, use
get_secure_login_data()- Parameters
client_id (str) – The Client ID of your Azure App
redirect_uri (str) – The Redirect URI of your Azure App
- Returns
The url to the website on which the user logs in
- Return type
str
- generate_state() str
Generates a random state
- Return type
str
- get_secure_login_data(client_id: str, redirect_uri: str, state: Optional[str] = None) Tuple[str, str, str]
Generates the login data for a secure login with pkce and state.Prevents Cross-Site Request Forgery attacks and authorization code injection attacks.
- Parameters
client_id (str) – The Client ID of your Azure App
redirect_uri (str) – The Redirect URI of your Azure App
state (Optional[str]) – You can use a existing state. If not set, a state will be generated using
generate_state().
- Return type
Tuple[str, str, str]
- url_contains_auth_code(url: str) bool
Checks if the given url contains a authorization code
- Parameters
url (str) – The URL to check
- Return type
bool
- get_auth_code_from_url(url: str) Optional[str]
Get the authorization code from the url.If you want to check the state, use
parse_auth_code_url(), which throws errors instead of returning an optional value.- Parameters
url (str) – The URL to parse
- Returns
The auth code or None if the the code is nonexistent
- Return type
Optional[str]
- parse_auth_code_url(url: str, state: Optional[str]) str
Parse the authorization code url and checks the state.
- Parameters
url (str) – The URL to parse
state (Optional[str]) – If set, the function raises a AssertionError, if the state do no match the state in the URL
- Returns
The auth code
- Return type
str
- get_authorization_token(client_id: str, client_secret: Optional[str], redirect_uri: str, auth_code: str, code_verifier: Optional[str] = None) AuthorizationTokenResponse
Get the authorization token. This function is called during
complete_login(), so you need to use this function ony ifcomplete_login()doesnt’t work for you.- Parameters
client_id (str) – The Client ID of your Azure App
client_secret (Optional[str]) – The Client Secret of your Azure App. This is deprecated and should not been used anymore.
redirect_uri (str) – The Redirect URI of your Azure App
auth_code (str) – The Code you get from
parse_auth_code_url()code_verifier (Optional[str]) – The 3rd entry in the Tuple you get from
get_secure_login_data()
- Return type
- refresh_authorization_token(client_id: str, client_secret: Optional[str], redirect_uri: Optional[str], refresh_token: str) AuthorizationTokenResponse
Refresh the authorization token. This function is called during
complete_refresh(), so you need to use this function ony ifcomplete_refresh()doesnt’t work for you.- Parameters
client_id (str) – The Client ID of your Azure App
client_secret (Optional[str]) – The Client Secret of your Azure App. This is deprecated and should not been used anymore.
redirect_uri (Optional[str]) – The Redirect URI of Azure App. This Parameter only exists for backwards compatibility and is not used anymore.
refresh_token (str) – Your refresh token
- Return type
- authenticate_with_xbl(access_token: str) XBLResponse
Authenticate with Xbox Live. This function is called during
complete_login(), so you need to use this function ony ifcomplete_login()doesnt’t work for you.- Parameters
access_token (str) – The Token you get from
get_authorization_token()- Return type
- authenticate_with_xsts(xbl_token: str) XSTSResponse
Authenticate with XSTS. This function is called during
complete_login(), so you need to use this function ony ifcomplete_login()doesnt’t work for you.- Parameters
xbl_token (str) – The Token you get from
authenticate_with_xbl()- Return type
- authenticate_with_minecraft(userhash: str, xsts_token: str) MinecraftAuthenticateResponse
Authenticate with Minecraft. This function is called during
complete_login(), so you need to use this function ony ifcomplete_login()doesnt’t work for you.- Parameters
userhash (str) – The Hash you get from
authenticate_with_xbl()xsts_token (str) – The Token you get from
authenticate_with_xsts()
- Return type
- get_store_information(access_token: str) MinecraftStoreResponse
Get the store information.
- Parameters
access_token (str) – The Token you get from
authenticate_with_minecraft()- Return type
- get_profile(access_token: str) MinecraftProfileResponse
Get the profile. This function is called during
complete_login(), so you need to use this function ony ifcomplete_login()doesnt’t work for you.- Parameters
access_token (str) – The Token you get from
authenticate_with_minecraft()- Return type
- complete_login(client_id: str, client_secret: Optional[str], redirect_uri: str, auth_code: str, code_verifier: Optional[str] = None) CompleteLoginResponse
Do the complete login process.
- Parameters
client_id (str) – The Client ID of your Azure App
client_secret (Optional[str]) – The Client Secret of your Azure App. This is deprecated and should not been used anymore.
redirect_uri (str) – The Redirect URI of your Azure App
auth_code (str) – The Code you get from
parse_auth_code_url()code_verifier (Optional[str]) – The 3rd entry in the Tuple you get from
get_secure_login_data()
- Raises
AzureAppNotPermitted – Your Azure App don’t have the Permission to use the Minecraft API
- Return type
It returns the following:
{ "id" : "The uuid", "name" : "The username", "access_token": "The acces token", "refresh_token": "The refresh token", "skins" : [{ "id" : "6a6e65e5-76dd-4c3c-a625-162924514568", "state" : "ACTIVE", "url" : "http://textures.minecraft.net/texture/1a4af718455d4aab528e7a61f86fa25e6a369d1768dcb13f7df319a713eb810b", "variant" : "CLASSIC", "alias" : "STEVE" } ], "capes" : [] }
- complete_refresh(client_id: str, client_secret: Optional[str], redirect_uri: Optional[str], refresh_token: str) CompleteLoginResponse
Do the complete login process with a refresh token. It returns the same as
complete_login().- Parameters
client_id (str) – The Client ID of your Azure App
client_secret (Optional[str]) – The Client Secret of your Azure App. This is deprecated and should not been used anymore.
redirect_uri (Optional[str]) – The Redirect URI of Azure App. This Parameter only exists for backwards compatibility and is not used anymore.
refresh_token (str) – Your refresh token
- Raises
InvalidRefreshToken – Your refresh token is not valid
- Return type
Raises a
InvalidRefreshTokenexception when the refresh token is invalid.