-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjusted according to review comments and other improvements
- Loading branch information
1 parent
c1b281d
commit e098335
Showing
5 changed files
with
96 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import base64 | ||
from typing import Mapping | ||
|
||
# Using the same http client as sumo | ||
import httpx | ||
|
||
|
||
class GraphApiAccess: | ||
def __init__(self, access_token: str): | ||
self._access_token = access_token | ||
|
||
def _make_headers(self) -> Mapping[str, str]: | ||
return {"Authorization": f"Bearer {self._access_token}"} | ||
|
||
async def _request(self, url: str) -> httpx.Response: | ||
async with httpx.AsyncClient() as client: | ||
response = await client.get( | ||
url, | ||
headers=self._make_headers(), | ||
) | ||
return response | ||
|
||
async def get_user_profile_photo(self) -> str | None: | ||
print("entering get_user_profile_photo") | ||
response = await self._request("https://graph.microsoft.com/v1.0/me/photo/$value") | ||
|
||
if response.status_code == 200: | ||
return base64.b64encode(response.content) | ||
else: | ||
return None | ||
|
||
async def get_user_info(self) -> Mapping[str, str] | None: | ||
print("entering get_user_info") | ||
response = await self._request("https://graph.microsoft.com/v1.0/me") | ||
|
||
if response.status_code == 200: | ||
return response.json() | ||
else: | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters