Add custom theme support, token refresh settings and check account login status.
Now launch log viewer has a new look. Fix an issue that causes credentials method option not working. Add log view to settings page.
This commit is contained in:
1 parent
6e29fe1d5c
commit
1bafc60d95
25 files changed
+1149
-199
No files matched your search
@@ -166,7 +166,7 @@ def _check_account(account: dict, account_id: str | None = None, fix_wrong: bool
|
||||
)
|
||||
|
||||
# Check all required key is exiting
|
||||
if any(not isinstance(account.get(key), str) or not account[key] for key in required_strings):
|
||||
if any(not isinstance(account.get(key), str) or key not in account for key in required_strings):
|
||||
return False
|
||||
|
||||
# Check account id is match as provided
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Store all function for microsoft authentication
|
||||
Store all function for Microsoft authentication
|
||||
|
||||
WARNING: This module is vibed! With code reviewed!
|
||||
"""
|
||||
@@ -11,7 +11,7 @@ from typing import Callable
|
||||
import requests
|
||||
|
||||
from core_lib.common.exception import AuthenticationSessionException, AuthenticationConnectException, \
|
||||
AuthenticationException
|
||||
AuthenticationException, LauncherHTTPException
|
||||
|
||||
MICROSOFT_DEVICE_CODE_URL = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"
|
||||
MICROSOFT_TOKEN_URL = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
|
||||
@@ -462,3 +462,39 @@ def refresh_microsoft_token(client_id: str, refresh_token: str) -> tuple[str, st
|
||||
result,
|
||||
)
|
||||
|
||||
def is_access_token_valid(minecraft_access_token: str) -> bool:
|
||||
"""
|
||||
Check if the access token is valid
|
||||
:param minecraft_access_token:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
response = requests.get(
|
||||
MINECRAFT_PROFILE_URL,
|
||||
headers={"Authorization": f"Bearer {minecraft_access_token}"},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception as e:
|
||||
raise AuthenticationSessionException(
|
||||
status_code=None,
|
||||
user_message="An error occurred while connecting to Minecraft API.",
|
||||
) from e
|
||||
|
||||
status_code = response.status_code
|
||||
|
||||
if status_code == 400:
|
||||
raise AuthenticationException(
|
||||
user_message="Got bad request response from Minecraft API. Client request format may outdated.",
|
||||
)
|
||||
elif status_code == 401:
|
||||
# Session is invalid
|
||||
return False
|
||||
|
||||
if status_code != 200:
|
||||
raise AuthenticationSessionException(
|
||||
"Get HTTP status code {} while fetch profile data for verifying access token".format(status_code),
|
||||
status_code=response.status_code,
|
||||
user_message="Unable to verify access token. An server error occurred. ({})".format(status_code),
|
||||
)
|
||||
|
||||
return True
|
||||
@@ -490,3 +490,26 @@ def update_profile(profiles: dict, profile_id: str, profile_data: dict, fix_wron
|
||||
|
||||
return profiles, profile_id
|
||||
|
||||
def set_last_used_time(profiles: dict, profile_id: str, time: datetime.datetime):
|
||||
"""
|
||||
Set profile last used time.
|
||||
:param profiles: Profiles data
|
||||
:param profile_id: Target profile ID.
|
||||
:param time: The time to set
|
||||
:return:
|
||||
"""
|
||||
if not is_profile_exists(profiles, profile_id):
|
||||
raise ProfileException(
|
||||
"Specified profile id {} not found.".format(profile_id)
|
||||
)
|
||||
|
||||
profiles["profiles"][profile_id]["lastUsed"] = time.isoformat().replace("+00:00", "Z")
|
||||
|
||||
def set_last_used_time_to_current(profiles: dict, profile_id: str):
|
||||
"""
|
||||
Set profile last used time to the current time.
|
||||
:param profiles: Profiles data
|
||||
:param profile_id: Target profile ID.
|
||||
:return:
|
||||
"""
|
||||
set_last_used_time(profiles, profile_id, datetime.datetime.now(datetime.timezone.utc))
|
||||
Reference in new issue
Block a user