Skip to content

Commit 39888ab

Browse files
committed
Change github_auth to save the user avatar.png if it doesn't exist and to use it going forward
1 parent 1df4a41 commit 39888ab

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

llms/extensions/github_auth/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,22 @@ async def github_callback_handler(request):
164164
if error_response:
165165
return error_response
166166

167+
user = user_data.get("login", "")
168+
profile_url = user_data.get("avatar_url", "")
169+
user_avatar_path = os.path.join(ctx.get_user_path(user), "avatar.png")
170+
if not os.path.exists(user_avatar_path):
171+
# download and save avatar
172+
async with aiohttp.ClientSession() as session, session.get(profile_url) as resp:
173+
with open(user_avatar_path, "wb") as f:
174+
f.write(await resp.read())
175+
167176
# Create session
168177
session_token = secrets.token_urlsafe(32)
169178
ctx.sessions[session_token] = {
170179
"userId": str(user_data.get("id", "")),
171-
"userName": user_data.get("login", ""),
180+
"userName": user,
172181
"displayName": user_data.get("name", ""),
173-
"profileUrl": user_data.get("avatar_url", ""),
182+
"profileUrl": profile_url,
174183
"email": user_data.get("email", ""),
175184
"created": time.time(),
176185
}
@@ -215,12 +224,13 @@ async def auth_handler(request):
215224

216225
if session_token and session_token in g_app.sessions:
217226
session_data = g_app.sessions[session_token]
227+
218228
return web.json_response(
219229
{
220230
"userId": session_data.get("userId", ""),
221231
"userName": session_data.get("userName", ""),
222232
"displayName": session_data.get("displayName", ""),
223-
"profileUrl": session_data.get("profileUrl", ""),
233+
"profileUrl": "/avatar/user",
224234
"authProvider": "github",
225235
}
226236
)

0 commit comments

Comments
 (0)