# Third-party applications

> Integrate with branchd over OAuth, asking for the least scopes and resources you need.
An application that acts for branchd users signs them in with
[Xeonr Auth](https://docs.xeonr.io/auth/guides/authorization-code) and calls branchd with
the access token. branchd gives a third-party token **exactly the scopes
it was granted**, never more, and always within the person's own role.

## Ask for the least

- **Ask for feature scopes**, not levels: `forge:contents:read` to clone,
  `forge:package:read` to pull images, `forge:check:edit` to report a
  check. See [Scopes and levels](https://docs.branchd.run/branchd/access/scopes).
- **Name the scopes you can't work without** in
  [`required_scope`](https://docs.xeonr.io/auth/guides/consent-narrowing#marking-scopes-as-required-required_scope).
  The person may untick the rest.
- **Limit to resources when you can.** Push `authorization_details`
  through [PAR](https://docs.xeonr.io/auth/guides/rar#using-par), with
  `resource=https://branchd.run`:

```json
[
  { "type": "forge:repository", "identifier": "acme/api", "actions": ["forge:contents:read"] },
  { "type": "forge:group", "identifier": "acme/docs", "actions": ["forge:contents:read", "forge:pull-request:edit"] }
]
```

Each action must be one of the scopes you asked for, or implied by one.

## Read what was granted

The person may untick scopes, drop resources you pushed, or limit an
unlimited request to some groups and repositories on the consent screen.
Read the `scope` and `authorization_details` in the token response, and
build your UI from those. See
[What the person grants](https://docs.xeonr.io/auth/guides/consent-narrowing).

A request outside the token's resources is refused, even where the
person's own role would allow it.

Source: https://docs.branchd.run/branchd/access/third-party-apps
