Skip to content

Commit

Permalink
docs: document AppInstallationAuth.get_token()
Browse files Browse the repository at this point in the history
  • Loading branch information
shtrom authored and ahal committed Jan 8, 2025
1 parent f2b53b5 commit 5667abd
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
Expand Up @@ -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:[email protected]/mozilla-releng/simple-github
```

### No Authentication

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

0 comments on commit 5667abd

Please sign in to comment.