# Pushed authorization requests

> The app sends its sign-in request straight to the realm and gives the browser only a short reference, so nothing in it can be read or changed on the way.

In a plain [sign-in](../../single-sign-on/authorization-code/), the app's request travels in the browser's address bar, where anyone
handling the URL can read or change it. With a pushed request, the app first sends the whole request to the realm
directly, proving who it is as it would at the token endpoint. The realm checks it and answers with a short
reference, and the browser carries only that.

Use it for any confidential app that can make the extra call, and always for high-security apps: the
[FAPI 2.0 profile](../security-profiles/) requires it. You can require it for one client or for the whole realm. A
single-page app can push from the browser too; [browser apps](../../single-sign-on/browser-apps/) says which sites may read the answer.

## Before you begin

- **Who can do it:** the app pushes its own requests with no setting. A realm administrator (a group holding
  `RealmOwner`) can require it of a client or the realm; `RealmViewer` can read those settings.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** the app authenticates at the token endpoint, or is a browser app allowed from its site.

## How it works

**1. The app pushes its request** from its back end, with the same parameters it would put in the address bar, and
proves who it is ([client authentication](../client-authentication/)):

```sh
curl https://foobar.cvyuh.com/oauth2/par \
  -u team-wiki:s6BhdRkqt3 \
  -d response_type=code \
  -d client_id=team-wiki \
  --data-urlencode redirect_uri=https://wiki.example.com/callback \
  --data-urlencode 'scope=openid profile' \
  -d state=af0ifjsldkj \
  -d code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM \
  -d code_challenge_method=S256
```

The realm checks it as it would check a sign-in request, and answers `201 Created`:

```json
{
  "request_uri": "urn:ietf:params:oauth:request_uri:eyJhbGciOi…",
  "expires_in": 60
}
```

**2. The app sends the browser** to the realm with only its `client_id` and the reference:

```http
GET /oauth2/authorize?client_id=team-wiki&request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3AeyJhbGciOi…
Host: foobar.cvyuh.com
```

From here the sign-in goes on as any other. A push may carry a signed request object ([Signed request objects](../request-objects/)) in place
of the plain parameters, and a [DPoP](../dpop/) proof, which binds the sign-in's code to that key as a `dpop_jkt` in
the request would.

## Set it up

Require pushing for one client in
`https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Client` (see [Call the API](../../../../develop/api/)), or for the whole realm with
`PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings`:

| Where | Setting | What it does |
|---|---|---|
| Realm | `requirePushedAuthorizationRequests` | Every sign-in in the realm must be pushed (default off) |
| Client | `requirePushedAuthorizationRequests` | This client's sign-ins must be pushed (default off) |
| Client | `securityProfile` | `fapi2` requires every sign-in to be pushed |
| Realm | `parLifetimeSecs` | How long a reference lives (default 60) |

The app pushes to `https://foobar.cvyuh.com/oauth2/par`. Discovery publishes it as
`pushed_authorization_request_endpoint` while the realm takes the authorization code grant.

## What the user sees

Nothing different: the browser goes to the realm's sign-in page with a short reference in place of the request. If
the reference has expired or was used, the user sees the realm's error page and starts again from the app.

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `parLifetimeSecs`: how long a reference lives | 60 | 10 to 600 |
| Uses per reference | one, by the client that pushed it | fixed |
| `requirePushedAuthorizationRequests`, realm or client | off | on or off; forced on for `fapi2` |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The user sees `invalid_request_uri` on the realm's error page | The app took more than a minute to redirect, or reused a reference | Push right before redirecting, a new push each time |
| The realm's error page for every sign-in of one client | It must push and sent the request through the browser | Push first, then send only `client_id` and `request_uri` |
| `invalid_request` at the push | A `request_uri` in the push, or an unregistered `redirect_uri` | Push the parameters themselves, with a registered address |

## Audit record

A push writes no record of its own. The sign-in it leads to writes `LOGIN` and its steps, and the code's redemption
a `TOKEN_ISSUED` record. Changes to the requirement are in **Audit → Config**.

## Good to know

- **A bad request is refused to the app's back end**, as an error it reads, never shown in the browser.
- **A reference works once**, for one minute by default, and only beside the client it was made for.
- **The realm accepts only its own references.** It never fetches a request from an address the request names. A
  push that itself carries a `request_uri` is refused.
- **The pushed request names one client.** A `client_id` in the body other than the one that authenticated is
  refused.
- **A `dpop_jkt` naming another key than the push's DPoP proof is refused.**
- **A client that must push and doesn't** is shown the realm's error page, and the app is told nothing.

## Reference

### Errors

At the push, the app reads the error in the answer:

| Error | When |
|---|---|
| `invalid_client` (401) | The client didn't prove who it is |
| `invalid_request` | The push carries a `request_uri`; names another client; has a missing or unregistered `redirect_uri`; or is otherwise malformed |
| `unauthorized_client` | The client may not use the authorization code grant, or is an agent's |
| `invalid_dpop_proof` | The DPoP proof is bad, or `dpop_jkt` names another key than the proof |
| `invalid_scope`, `invalid_target` | A scope or a resource the client may not ask for |
| `invalid_request_object` | A request object that doesn't verify |

At `/authorize`, a reference that is spent, expired, another client's or not the realm's own is
`invalid_request_uri`, shown on the realm's error page.

## Related

- [Make sign-in requests tamper-proof](../../../guides/sign-in-to-apps/tighten-sign-in-requests/): pushing and
  signing requests, start to finish.
- [Hold a client to FAPI 2.0](../../../guides/services/fapi2-clients/): where pushing is
  required.
- [Signed request objects](../request-objects/): the other way to protect a request.
- [Security profiles](../security-profiles/): named minimums that include pushing.
