From 273399415362a9f05a6bd7bfc8aefad83259dd44 Mon Sep 17 00:00:00 2001 From: Nightriff <66378309+Nightriff@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:53:33 -0700 Subject: [PATCH] Use Display Name instead of Username (#23) --- __init__.py | 2 +- lib/oauth2_client.py | 10 +++++----- lib/request_login_details.py | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/__init__.py b/__init__.py index 2f3c3eb..7f62aa8 100644 --- a/__init__.py +++ b/__init__.py @@ -181,7 +181,7 @@ def draw(self, context): from .lib.oauth2_client import RbxOAuth2Client oauth2_client = RbxOAuth2Client(rbx) - top_row.label(text=f"Hello, {oauth2_client.preferred_username}") + top_row.label(text=f"Hello, {oauth2_client.name}") except Exception as exception: self.report({"ERROR"}, f"{str(exception)}\n{traceback.format_exc()}") diff --git a/lib/oauth2_client.py b/lib/oauth2_client.py index 247dfd4..119341f 100644 --- a/lib/oauth2_client.py +++ b/lib/oauth2_client.py @@ -249,10 +249,10 @@ async def refresh_login_if_needed(self): self.__complete_login(*await request_login_details(new_token_data)) - def __complete_login(self, creator_ids, preferred_username, group_names_by_id, token_data): + def __complete_login(self, creator_ids, name, group_names_by_id, token_data): # Set state values in rbx from the data fetched and processed above - self.__set_creators_from_ids(creator_ids, preferred_username, group_names_by_id) - self.preferred_username = preferred_username + self.__set_creators_from_ids(creator_ids, name, group_names_by_id) + self.name = name self.token_data = token_data self.rbx.is_logged_in = True @@ -321,7 +321,7 @@ async def __refresh_tokens(self, refresh_token): exception.message = error_description raise exception - def __set_creators_from_ids(self, creator_ids, preferred_username, group_names_by_id): + def __set_creators_from_ids(self, creator_ids, name, group_names_by_id): """Populates a CollectionProperty with RbxCreatorData objects containing creator types, ids, and names given ids and names. Used for persisting creator data across sessions and generating enum dropdown items. """ @@ -332,7 +332,7 @@ def __set_creators_from_ids(self, creator_ids, preferred_username, group_names_b creator = self.rbx.creators.add() creator.type = "USER" creator.id = creator_ids["user"] - creator.name = preferred_username + creator.name = name for group_id in creator_ids["groups"]: creator = self.rbx.creators.add() diff --git a/lib/request_login_details.py b/lib/request_login_details.py index 0f54618..90bcf23 100644 --- a/lib/request_login_details.py +++ b/lib/request_login_details.py @@ -75,8 +75,8 @@ async def request_login_details(token_data): # Raises jwt.exceptions.DecodeError profile_data = await __decode_id_token(token_data.get("id_token")) - # Raises KeyError if missing preferred_username - preferred_username = profile_data["preferred_username"] + # Raises KeyError if missing name + name = profile_data["name"] token_data = { "refresh_after": time() + token_data["expires_in"] - REFRESH_SECONDS_BEFORE_EXPIRY, @@ -85,7 +85,7 @@ async def request_login_details(token_data): "id_token": token_data["id_token"], } - return creator_ids, preferred_username, group_names_by_id, token_data + return creator_ids, name, group_names_by_id, token_data async def __request_authorized_resources(access_token):