> For the complete documentation index, see [llms.txt](https://docs.openiam.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openiam.com/administration-guide/privacy/enforce-consent-at-the-gateway.md).

# Ask for consent at the gateway

Make an application behind the Access Gateway depend on a person's consent, and send a browser that lacks it to a consent page — then back — instead of an error, while API callers get a 401 that names

**Applies to:** OpenIAM 2026.11.1

## What this is, and when you need it

A PBAC policy can make an application behind the Access Gateway reachable only while the person has granted consent for a purpose. With **just-in-time consent**, a browser refused *only* because consent is missing is sent to a consent page that shows the notice, records the grant and returns the person to where they were going; an API call gets `401` with a header naming the purpose.

The redirect is the point of doing it this way: without it, somebody who has simply never been asked meets a refusal they cannot act on. It is also the part that leans on infrastructure you may not own. OpenIAM can only tell a browser from an API client if the reverse proxy forwards three request headers, and a person who has never opened the Privacy Center has no privacy subject at all, so they get a plain refusal instead of the consent page. Settle both before gating anything people actually use.

The policy itself is [Privacy decisions](https://docs.openiam.com/administration-guide/pbac/privacy-decisions.md). Gating sign-in on an acceptable-use text is [Consent and IT policy](https://docs.openiam.com/administration-guide/consent/consent-and-it-policy.md).

## At a glance

|                          |                                                                                                                                                                |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **You will end up with** | An application URL that loads with consent, and without it sends a browser to a consent page and back                                                          |
| **Where**                | **Administration → PBAC Policies** for the policy; the content provider screen, `/webconsole/editContentProvider?providerId=<CP_ID>`, for **Consent page URL** |
| **You need first**       | An `ACTIVE` consent-based purpose with an `ACTIVE` notice; PBAC enabled at the gateway                                                                         |
| **Takes**                | 30 minutes, plus propagation                                                                                                                                   |
| **Reversible**           | Yes — deprecate the policy, and the URL is decided without consent again                                                                                       |

## Before you begin

**The deployment owner turns the gateway check on** — `org.openiam.pbac.gateway.enabled` on the `openiam-esb` service ships `false`. The consent page is then on by default (`org.openiam.privacy.consent.redirect.enabled` ships `true`). Each is a properties change with a restart — [Installation and Tuning Guide](https://docs.openiam.com/installation/settings.md).

**The reverse proxy must pass `Sec-Fetch-Mode`, `X-Requested-With` and `Accept` to OpenIAM**, which tells a browser navigation from an API call by them. Without them every consent refusal is a `401` and nobody is redirected — it fails safe, not open.

**Each person must have opened the Privacy Center once.** Without a privacy subject they are refused as `REVIEW_REQUIRED`, not for consent, and get the plain refusal. **Never put the policy on `/selfservice-v2/*`**: the consent page lives there.

## Set it up

{% stepper %}
{% step %}
Find the resource to protect. Open the content provider, then the URI pattern for the application path — `/crm/*`, say — and note the resource attached to the pattern. That resource is what the policy targets.
{% endstep %}

{% step %}
In **Administration → PBAC Policies**, make sure an **enforced** policy already decides that resource — for example a permit for your administrators' role. Without one, a consent policy in `SHADOW` refuses every request; see [Roll a consent policy out](https://docs.openiam.com/administration-guide/pbac/privacy-decisions.md#roll-a-consent-policy-out).
{% endstep %}

{% step %}
Create the consent policy. **Resource**: the pattern's resource. **Privacy** → **Requires consent for purpose**: your purpose; the builder adds the *consent state is GRANTED* condition. Save it, activate it in `SHADOW`, and read its rows in the decision log, filtered to **Class** `Privacy`. When they read right, move it to `FULL`.

{% code overflow="wrap" %}

```cedar
@privacy_purpose("<PURPOSE_ID>")
permit (principal, action, resource == Openiam::Resource::"<PATTERN_RESOURCE_ID>")
when { context.privacy.consentState == "GRANTED" };
```

{% endcode %}
{% endstep %}

{% step %}
Optional: send this application's people to a page of your own. On the content provider screen, set **Consent page URL** — directly under **Unavailable URL** — to a path on the provider's host, such as `/selfservice-v2/consent-required`, or to an absolute `https://` URL. Leave it empty to use the platform default. Any other value is refused when you save. Click **Save**.
{% endstep %}

{% step %}
Wait for the policy to reach the engine and for the gateway's memory of the resource as unprotected to expire — `org.openiam.pbac.gateway.no.policy.cache.ms`, one minute as shipped.
{% endstep %}
{% endstepper %}

## What the person sees

A person without consent who opens the application in a browser lands on **Your consent is needed** — `The application you opened needs your consent for one purpose before it can continue.` — with the purpose, its description, **Data used:**, the notice that covers it, and a sentence for their situation:

| Consent state                                                                                        | The page says                                                                                                           |
| ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Never asked                                                                                          | `You have not been asked about this purpose yet. Give your consent to continue, or come back later.`                    |
| Withdrawn                                                                                            | `You withdrew your consent for this purpose. To continue, you can give it again.`                                       |
| Declined                                                                                             | `You declined this purpose earlier. To continue, you can give your consent now.`                                        |
| Expired                                                                                              | `Your consent for this purpose has expired. To continue, please give it again.`                                         |
| Granted on a notice since replaced by a material change, under **Block processing until re-consent** | `The notice behind your consent has changed in a material way. Please read it and re-confirm your consent to continue.` |

**Give consent** (**Re-confirm consent** in the last case) opens the same dialog as the Privacy Center; after **I agree** the page shows `Taking you back to the application…` and returns the person to the URL they were opening. **Not now** leaves them on the page with `No consent was given, so the application stays unavailable for this purpose.` A purpose not offered to them, or no longer `ACTIVE`, cannot be granted here: the page says so and links to the Privacy Center.

## The contract

This is what the gateway, the consent page and an application in front of OpenIAM can rely on.

### Which refusals are consent refusals

Only a `DENY` that the consent check itself produced, for the purpose the decision was about, counts: consent never given, `DENIED`, `WITHDRAWN` or `EXPIRED`, or a grant blocked by a material notice change under **Block processing until re-consent**. Everything else — a forbid, an inactive purpose, an unknown person, a missing or expired lawful authority, `REVIEW_REQUIRED` under **Require re-consent (route to review)**, an unhonored mandatory obligation, an engine failure — is refused as before, because granting consent would not let the request through. When one URL touches several resources and any of them is refused for a reason other than consent, that refusal wins.

### What the gateway answers

| Request                                                                                                                                                | Answer                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Browser navigation — `Sec-Fetch-Mode: navigate`; or, without that header, an `Accept` containing `text/html` and no `X-Requested-With: XMLHttpRequest` | A redirect to the content provider's **Consent page URL**, or to `org.openiam.privacy.consent.page.url` when it is empty, with `purposeId`, `cpId` and `returnTo` appended. The redirect is never cached |
| Anything else — an API call, an `XMLHttpRequest`, a request that carries none of the three headers                                                     | `401`, with the `X-OpenIAM-Privacy-Decision` header                                                                                                                                                      |
| Any request, with `org.openiam.privacy.consent.redirect.enabled` set to `false`                                                                        | `401`, with the header                                                                                                                                                                                   |

The header names the decision, the purpose and the state:

{% code overflow="wrap" %}

```
X-OpenIAM-Privacy-Decision: CONSENT_REQUIRED; purpose=<PURPOSE_ID>; state=WITHDRAWN
```

{% endcode %}

`state` is `NONE`, `DENIED`, `WITHDRAWN`, `EXPIRED` or `REVIEW` — the last meaning a grant blocked by a material notice change. A refusal that is not a consent refusal carries no such header.

Webconsole and SelfService REST methods guarded by PBAC answer a consent refusal the same way: `401`, the same header, and the message `Your consent for the purpose <PURPOSE_ID> is required before this request can go ahead.` with the error token `PRIVACY_CONSENT_REQUIRED`.

### Where the person is sent back

The consent page never follows `returnTo` as given. It asks OpenIAM to resolve it against `cpId`, and the URL is used only if it is `http` or `https`, belongs to that same content provider, and matches one of its URI patterns. Anything else is replaced by the content provider's landing page; an unknown `cpId` leaves the person on the consent page with `Your consent was recorded. Go back to the application yourself, or open the Privacy Center.` So the page cannot be used to send people to another site.

## Verification

| What to check                   | How                                                                                                                                                                                            |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The policy decides the resource | Decision log, **Class** `Privacy`, **Purpose** your purpose: a `DENY` for the test person before they consent, an `ALLOW` after                                                                |
| A browser is redirected         | As a test person who has opened the Privacy Center but not consented, open the application: you land on **Your consent is needed**, and the address carries `purposeId`, `cpId` and `returnTo` |
| The round trip completes        | **Give consent** → **I agree**: you are back on the application page you opened                                                                                                                |
| An API caller gets the header   | Call a URL under the pattern with `X-Requested-With: XMLHttpRequest` as a person without consent: `401` with `X-OpenIAM-Privacy-Decision: CONSENT_REQUIRED; purpose=…; state=NONE`             |
| The redirect is in the log      | The `openiam-esb` log line `PBAC requires consent (CONSENT_REQUIRED; purpose=…) on <url>; redirecting the navigation to <page>`                                                                |

## When it goes wrong

| Symptom                                                                                                           | Likely cause                                                                                                                                                  | Resolution                                                                                                                                                                  |
| ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Every consent refusal is a `401`, never a redirect                                                                | The reverse proxy does not forward `Sec-Fetch-Mode`, `Accept` and `X-Requested-With` to OpenIAM, or `org.openiam.privacy.consent.redirect.enabled` is `false` | Have the gateway owner forward the three headers; check the property with the deployment owner                                                                              |
| A person who has never used the Privacy Center gets a plain refusal                                               | No privacy subject exists for them, so the decision is `REVIEW_REQUIRED`                                                                                      | Have them open SelfService → **Privacy Center** once                                                                                                                        |
| A person with consent under **Require re-consent (route to review)** gets a plain refusal after a material change | That behavior produces `REVIEW_REQUIRED`, not a consent refusal                                                                                               | Use **Block processing until re-consent** on notices for gateway-protected purposes, or have people re-confirm in the Privacy Center                                        |
| The consent page says the purpose is not offered                                                                  | The person is outside the purpose's audience, or the purpose is no longer `ACTIVE`                                                                            | Fix the audience or the purpose; see [Register purposes and lawful authorities](https://docs.openiam.com/administration-guide/privacy/register-purposes-and-authorities.md) |
| After consenting the person stays on the consent page                                                             | `returnTo` did not resolve to a URL of the same content provider, or `cpId` is unknown                                                                        | Check the content provider's URI patterns cover the URL being opened                                                                                                        |
| The person is sent back and sent to the consent page again                                                        | Another purpose on the same resource also requires consent                                                                                                    | Each purpose is asked for in turn; the second redirect names the next one                                                                                                   |
| Saving the content provider is refused after you set **Consent page URL**                                         | The value is neither a path starting with `/` nor an absolute `http`/`https` URL                                                                              | Correct the value, or clear it                                                                                                                                              |
| The policy has no effect at all                                                                                   | `org.openiam.pbac.gateway.enabled` is `false`, or the propagation wait has not passed                                                                         | See [Privacy decisions](https://docs.openiam.com/administration-guide/pbac/privacy-decisions.md#when-it-goes-wrong)                                                         |

## Roll it back

Deprecate the consent policy; once the engine has picked that up the URL is decided by its entitlements and the remaining policies alone. Clearing **Consent page URL** returns the content provider to the platform default page. Consents recorded in the meantime stay in the ledger.

## Related

* [Privacy decisions](https://docs.openiam.com/administration-guide/pbac/privacy-decisions.md) — the policy, the privacy record and the gateway properties
* [What people see in the Privacy Center](https://docs.openiam.com/administration-guide/privacy/the-privacy-center.md) — the page people consent on
* [Content provider and URI pattern reference](https://docs.openiam.com/administration-guide/access/content-providers-and-uri-patterns/content-provider-reference.md) — every field on the content provider, including **Consent page URL**
* [Protect an application behind the Access Gateway](https://docs.openiam.com/administration-guide/gateway/protect-an-application.md) — publishing the application in the first place


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openiam.com/administration-guide/privacy/enforce-consent-at-the-gateway.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
