Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Display Name instead of Username #23

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")

Expand Down
10 changes: 5 additions & 5 deletions lib/oauth2_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
"""
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lib/request_login_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down