--- title: "ADR 0012: GitHub App tokens are minted before parsing and re-scoped after" --- * Status: accepted * Code: [`pkg/provider/github/parse_payload.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/parse_payload.go), [`pkg/provider/github/github.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/github.go) ## Context `ParsePayload` runs before `SetClient`. For pull request comments and re-checks from the UI, the payload does not contain the pull request, so the provider needs a token to call the API while it is still parsing. An App installed on an organisation that mixes private and public repositories could otherwise give an unscoped token to events from public users. ## Decision * `ParsePayload` mints an installation token first, from the installation ID in the payload, so the parse can call the API. At that point `RepositoryIDs` is not yet set from the payload, so this first token is not narrowed by `GetAppToken` unless an earlier caller set repository IDs or names. * `SetClient` (`setupAuthenticatedClient`) then calls `ScopeTokenToListOfRepos`. If that returns a token, it is used. Otherwise, when repository IDs or names are set, it mints a scoped token for the triggering repository only. The scoped mint is deferred until after `ScopeTokenToListOfRepos` so `CreateToken` can first look up extra repositories from the ConfigMap. * The token is requested eagerly (`itr.Token`) because it is needed to decide on private repositories. * `GetAppToken` overrides `itr.BaseURL` and `v.APIURL` with the URL from `AppTokenTestAPIURL` when one is set. This keeps token requests and API calls on one custom host when auth and API are decoupled, as with the `httptest` server in unit tests. ## Consequences * An App event makes two token requests, the second narrower than the first. * The first token is not scoped to the triggering repository when `ParsePayload` uses it.