Skip to content

Commit

Permalink
set trust_env=True (Chainlit#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard authored Oct 2, 2023
1 parent c4af86e commit 7f1a40f
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions backend/chainlit/oauth_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ async def get_token(self, code: str, url: str):
"client_secret": self.client_secret,
"code": code,
}
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.post(
"https://github.com/login/oauth/access_token",
json=payload,
Expand All @@ -58,7 +60,9 @@ async def get_token(self, code: str, url: str):
return token

async def get_user_info(self, token: str):
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.get(
"https://api.github.com/user",
headers={"Authorization": f"token {token}"},
Expand Down Expand Up @@ -103,7 +107,9 @@ async def get_token(self, code: str, url: str):
"grant_type": "authorization_code",
"redirect_uri": url,
}
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.post(
"https://oauth2.googleapis.com/token",
data=payload,
Expand All @@ -117,7 +123,9 @@ async def get_token(self, code: str, url: str):
return token

async def get_user_info(self, token: str):
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.get(
"https://www.googleapis.com/userinfo/v2/me",
headers={"Authorization": f"Bearer {token}"},
Expand Down Expand Up @@ -157,7 +165,9 @@ async def get_token(self, code: str, url: str):
"grant_type": "authorization_code",
"redirect_uri": url,
}
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.post(
"https://login.microsoftonline.com/common/oauth2/v2.0/token",
data=payload,
Expand All @@ -172,7 +182,9 @@ async def get_token(self, code: str, url: str):
return token

async def get_user_info(self, token: str):
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.get(
"https://graph.microsoft.com/v1.0/me",
headers={"Authorization": f"Bearer {token}"},
Expand Down Expand Up @@ -214,7 +226,9 @@ async def get_token(self, code: str, url: str):
"grant_type": "authorization_code",
"redirect_uri": url,
}
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.post(
f"{self.domain}/oauth2/default/v1/token",
data=payload,
Expand All @@ -229,7 +243,9 @@ async def get_token(self, code: str, url: str):
return token

async def get_user_info(self, token: str):
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.get(
f"{self.domain}/oauth2/default/v1/userinfo",
headers={"Authorization": f"Bearer {token}"},
Expand Down Expand Up @@ -268,7 +284,9 @@ async def get_token(self, code: str, url: str):
"grant_type": "authorization_code",
"redirect_uri": url,
}
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.post(
f"{self.domain}/oauth/token",
json=payload,
Expand All @@ -282,7 +300,9 @@ async def get_token(self, code: str, url: str):
return token

async def get_user_info(self, token: str):
async with aiohttp.ClientSession(raise_for_status=True) as session:
async with aiohttp.ClientSession(
trust_env=True, raise_for_status=True
) as session:
async with session.get(
f"{self.domain}/userinfo",
headers={"Authorization": f"Bearer {token}"},
Expand Down

0 comments on commit 7f1a40f

Please sign in to comment.