Fix auth issues with Installation.get_repos (#2547)

This commit is contained in:
Enrico Minack
2023-06-13 08:35:47 +02:00
committed by GitHub
parent daf62bd461
commit 6407512079
6 changed files with 96 additions and 0 deletions
+11
View File
@@ -35,6 +35,7 @@ import github.PaginatedList
import github.Plan
import github.Repository
import github.UserKey
from github.Auth import AppAuth
from . import Consts
@@ -46,6 +47,16 @@ class Installation(github.GithubObject.NonCompletableGithubObject):
This class represents Installations. The reference can be found here https://docs.github.com/en/rest/reference/apps#installations
"""
def __init__(self, requester, headers, attributes, completed):
super().__init__(requester, headers, attributes, completed)
auth = self._requester.auth if self._requester is not None else None
# Usually, an Installation is created from a Requester with App authentication
if isinstance(auth, AppAuth):
# But the installation has to authenticate as an installation (e.g. for get_repos())
auth = auth.get_installation_auth(self.id, requester=self._requester)
self._requester = self._requester.withAuth(auth)
def __repr__(self):
return self.get__repr__({"id": self._id.value})
+4
View File
@@ -343,6 +343,10 @@ class Requester:
def base_url(self):
return self.__base_url
@property
def auth(self):
return self.__auth
def withAuth(self, auth):
"""
Create a new requester instance with identical configuration but the given authentication method.
+2
View File
@@ -141,6 +141,8 @@ class Requester:
) -> None: ...
@property
def base_url(self) -> str: ...
@property
def auth(self) -> Optional[Auth]: ...
def withAuth(self, auth: Optional[Auth]) -> Requester: ...
def _initializeDebugFeature(self) -> None: ...
def check_me(self, obj: GithubObject) -> None: ...