mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-19 23:45:09 +00:00
Fix auth checking
This commit is contained in:
parent
a998593118
commit
66486211f3
2 changed files with 5 additions and 1 deletions
|
@ -16,6 +16,7 @@ __all__ = (
|
|||
'Paginator',
|
||||
'get_user',
|
||||
'get_repo_from_name',
|
||||
'get_repo_issue',
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ class GHClient:
|
|||
self._repo_cache = RepoCache(bound(50, 0, repo_cache_size))
|
||||
if username and token:
|
||||
self.username = username
|
||||
self.token = token
|
||||
self._auth = aiohttp.BasicAuth(username, token)
|
||||
|
||||
def __await__(self) -> 'GHClient':
|
||||
|
@ -65,11 +66,13 @@ class GHClient:
|
|||
if self.has_started:
|
||||
raise exceptions.AlreadyStarted
|
||||
if self._auth:
|
||||
self.session = await http.make_session(headers=self._headers, authorization=self._auth)
|
||||
try:
|
||||
await self.get_self()
|
||||
except exceptions.InvalidToken as 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
|
||||
return self
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue