Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document AppInstallationAuth.get_token() #52

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading