Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readme: document AppInstallationAuth.get_token()
Browse files Browse the repository at this point in the history
shtrom committed Dec 31, 2024
1 parent f2b53b5 commit 222001b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -105,6 +105,34 @@ async with AppClient(app_id, privkey) as session:
resp = await session.get("/octocat")
```

### Obtain an app token for use with git

Under the hood, the `AppClient` uses the `AppAuth` and `AppInstallationAuth`
objects to obtain a GitHub token. It can also be used to pull or push from a
repository.

The token can be obtained as follows for a given installation of the app.

```python
app_auth = AppAuth(app_id, privkey)
inst_auth = AppInstallationAuth(app_auth, owner, repositories=["simple-github"])
return await inst_auth.get_token()
```

The `get_token` method doesn't natively support synchronous calls, but it can
easily be called from synchronous code with

```python
return asyncio.run(inst_auth.get_token())
```

The returned token (`ghs_XXX`) can be used directly to authenticate git+http
operations as the `git` user.

```
git remote set-url origin https://git:ghs_XXX@github.com/mozilla-releng/simple-github
```

### No Authentication

Finally you can create a client without any authentication. This is mainly

0 comments on commit 222001b

Please sign in to comment.