1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-19 23:45:09 +00:00

Fix auth checking

This commit is contained in:
VarMonke 2022-04-04 18:59:28 +05:30
parent a998593118
commit 66486211f3
2 changed files with 5 additions and 1 deletions

View file

@ -16,6 +16,7 @@ __all__ = (
'Paginator', 'Paginator',
'get_user', 'get_user',
'get_repo_from_name', 'get_repo_from_name',
'get_repo_issue',
) )

View file

@ -33,6 +33,7 @@ class GHClient:
self._repo_cache = RepoCache(bound(50, 0, repo_cache_size)) self._repo_cache = RepoCache(bound(50, 0, repo_cache_size))
if username and token: if username and token:
self.username = username self.username = username
self.token = token
self._auth = aiohttp.BasicAuth(username, token) self._auth = aiohttp.BasicAuth(username, token)
def __await__(self) -> 'GHClient': def __await__(self) -> 'GHClient':
@ -65,11 +66,13 @@ class GHClient:
if self.has_started: if self.has_started:
raise exceptions.AlreadyStarted raise exceptions.AlreadyStarted
if self._auth: if self._auth:
self.session = await http.make_session(headers=self._headers, authorization=self._auth)
try: try:
await self.get_self() await self.get_self()
except exceptions.InvalidToken as exc: except exceptions.InvalidToken as exc:
raise exceptions.InvalidToken from exc raise exceptions.InvalidToken from exc
self.session = await http.make_session(headers=self._headers, authorization=self._auth) else:
self.session = await http.make_session(authorization = self._auth, headers = self._headers)
self.has_started = True self.has_started = True
return self return self