From 9dcc1fc489cc55fad36a6c21b7b3196234b372b4 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Thu, 14 Sep 2023 17:42:34 -0400 Subject: [PATCH] Remove GitHubAppClientFactory.create_app_client This method was mistakenly added with sufficient testing and never worked. The Gidgethub API cannot cache an app JWT with its current API. The documentation now features the correct workflow, which requires manually obtaining the JWT and passing it with each release. --- ...14_173515_jsick_DM_39710_remove_app_factory.md | 3 +++ .../github-apps/create-a-github-client.rst | 15 ++++++++++++--- src/safir/github/_client.py | 10 ---------- 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 changelog.d/20230914_173515_jsick_DM_39710_remove_app_factory.md diff --git a/changelog.d/20230914_173515_jsick_DM_39710_remove_app_factory.md b/changelog.d/20230914_173515_jsick_DM_39710_remove_app_factory.md new file mode 100644 index 00000000..4d7e7735 --- /dev/null +++ b/changelog.d/20230914_173515_jsick_DM_39710_remove_app_factory.md @@ -0,0 +1,3 @@ +### Backwards-incompatible changes + +- Remove the `GitHubAppClientFactory.create_app_client` method, which does not work with the Gidgethub API. Instead, the documentation shows how to create a JWT with the `GitHubAppClientFactory` and pass it with requests. diff --git a/docs/user-guide/github-apps/create-a-github-client.rst b/docs/user-guide/github-apps/create-a-github-client.rst index 6cf86bd6..d1fa0691 100644 --- a/docs/user-guide/github-apps/create-a-github-client.rst +++ b/docs/user-guide/github-apps/create-a-github-client.rst @@ -69,20 +69,29 @@ Authenticating as the app Your app can authenticate to GitHub in two modes: as the *app itself*, or as an *installation* of the app. Authenticating as the GitHub App enables your app to access information about the app itself, such as its installations. +To do this, get the app's JWT and use it with an GitHub client requests: + +.. code-block:: python + + client = github_client_factory.create_anonymous_client() + jwt = github_client_factory.get_app_jwt() + +Example of using the JWT to get the app's installations: + .. code-block:: python - app_client = github_client_factory.create_app_client() + data = await client.getitem("/app/installations", jwt=jwt) Authenticating as the app installation ====================================== To authenticate as an installation of the app, you need to know the installation ID. -Dependening on the scenario, there are multiple ways of getting the installation ID. +Depending on the scenario, there are multiple ways of getting the installation ID. In a webhook handler -------------------- -If your app recieves a webhook from GitHub, the installation ID will be included in the payload (as the ``installation.id`` field, see the `~safir.github.webhooks.GitHubAppInstallationModel`). +If your app receives a webhook from GitHub, the installation ID will be included in the payload (as the ``installation.id`` field, see the `~safir.github.webhooks.GitHubAppInstallationModel`). .. code-block:: python diff --git a/src/safir/github/_client.py b/src/safir/github/_client.py index cf64e286..64ad98e3 100644 --- a/src/safir/github/_client.py +++ b/src/safir/github/_client.py @@ -61,16 +61,6 @@ def create_anonymous_client(self) -> GitHubAPI: """ return self._create_client() - def create_app_client(self) -> GitHubAPI: - """Create a client authenticated as the GitHub App. - - Returns - ------- - gidgethub.httpx.GitHubAPI - The app client. - """ - return self._create_client(oauth_token=self.get_app_jwt()) - async def create_installation_client( self, installation_id: str ) -> GitHubAPI: