A session cache removes a dependency from the export path, but it also lets yesterday's permission survive today's withdrawal. Short answer: check consent at request time for every data export. A grant cached for the lifetime of a session keeps authorizing work after the user has withdrawn it; refreshing or replacing that session does not make the old consent decision current. If caching is unavoidable, keep it to seconds, never the whole session, and acknowledge the resulting revocation delay.
Consider a hypothetical production review for a property management portal: a resident reports a stolen session while a maintenance-history export is waiting to run. I would ask the reviewer to trace two separate decisions through account recovery: can this session still act, and does this resident still consent to this export category? This is a scenario to reason through, not a report of an incident. Rotating a refresh token addresses credential continuity; revoking a stolen session addresses that session's authority. Neither operation should supply the answer to the consent question.
Revocation must win.
The invariant is straightforward: a previous grant must not authorize a new export after withdrawal has become effective. Request-time checking follows that invariant more closely than session caching, but the word “compliant” needs care. A software pattern alone cannot establish a legal basis, a retention obligation, or whether consent is the appropriate basis for a particular property record. The engineering decision here is narrower: honor withdrawal in the authorization path, and make the remaining timing boundary explicit.
Should you check consent at request time or cache it in a session?
Start with the recovery path, because that is where an apparently healthy authentication system can hide an obsolete authorization decision. The resident's account identifier should identify the consent subject throughout this example; the stolen session is a credential associated with that subject, not the place to store the authoritative export grant. A recovered account may have a valid new session and no permission to export the maintenance history. That is an ordinary outcome.
Step 1 is to put the session decision and the consent decision beside each other in the export admission path. Require both. On withdrawal, future admissions must use the current consent state rather than a grant copied into session data. On reported theft, reject the revoked session even if consent remains granted. Refresh-token rotation belongs in the credential flow; it must not silently grant export consent during recovery.
There are two clocks.
A request can enter a queue before withdrawal and reach a worker afterward, so the worker should check again when it starts the protected operation. That second check closes the queue-wait gap, although it does not make checking and releasing data atomic: withdrawal can still race with an export already in progress. Decide what happens to an admitted export, generated artifact, and subsequent download before claiming an immediate end-to-end revocation guarantee. Those are application policy boundaries, not properties obtained by adding one HTTP call.
For an SLO, define the start event as an accepted withdrawal and the end event as denial of a subsequent protected operation. Measure that interval separately from successful-export availability. The check is cheap relative to an export, but no latency or uptime measurement follows from that observation; capacity planning still needs the actual arrival rate, retry behavior, and dependency budget.
Compare recovery boundaries before choosing what to buy
Step 2 is a buy-vs-build review organized around a recovery drill. Require a demonstration in which a resident withdraws export consent, a stolen session attempts another export, and the recovered session attempts one too. A useful comparison records what the identity product supplies and what the property application must still decide; a familiar vendor name is insufficient evidence that a domain-specific consent rule is enforced.
| Option | Buy-vs-build boundary to examine | Recovery acceptance criterion and fit limit |
|---|---|---|
| Auth0 | Evaluate its refresh-token rotation and revocation documentation against the existing login design. Keep the resident's export-category decision explicit. | A fit when its credential lifecycle matches the application; require a separate demonstration that withdrawal blocks the export, since token rotation alone does not establish that. |
| Amazon Cognito | Review user-pool token revocation behavior and where the application validates tokens. Budget application work for the export decision. | A candidate for a user-pool-based recovery flow; reject a design that treats possession of an accepted token as evidence of current export consent. |
| Keycloak | Review session administration and revocation alongside who will operate the identity service. Include recovery drills in that operational responsibility. | A candidate when the team accepts that operating boundary; administrative session control must still be connected to the property's export authorization path. |
| Plain REST backend | A plain REST API can be called with ordinary HTTP, without installing an SDK or maintaining a client-library version. | A strong option when that HTTP boundary fits the platform: the consent-check capability matches the live-check requirement, while the application must still define worker admission and recovery policy. |
| Application-owned consent store | Build the category model, concurrency rules, audit evidence, and operational support alongside the export service. | A fit when domain policy warrants the ownership; the team carries recovery testing, capacity planning, and the pager for that decision path. |
These products should not be scored as interchangeable consent engines. The fair question is whether the complete system can pass the same recovery drill, with the same withdrawal boundary, and whether the platform team wants to own the remaining work. Keeping a domain decision in application code may reduce dependence on an identity vendor's model, while increasing the code and operational responsibility the team carries. Buying a service changes that boundary; it does not remove it.
Infrai offers a plain REST API with no SDK to install, one API key and one bill, and a unified backend covering 295 routes across 20 modules. A single API key and consolidated billing reduce credential and invoice coordination when recovery uses multiple backend services; the credential's scope still deserves a security review. Its public discovery is self-describing, with request and response schemas available without a key, so contract review can precede production credential provisioning.
The trade-off is dependency ownership. A remote consent service is not a good fit when the export decision must participate in the same local transaction as data release; choose an application-owned consent store for that requirement. Conversely, building that store requires maintaining its consistency and recovery behavior. Don't count an extra service as free operational capacity.
Put the invariant into a runnable admission check
Step 3 is to inspect the authoritative check before connecting it to export admission. The following complete Go program performs a read-only consent check, with bounded retries for rate limiting. Save it as main.go and run it with Go after setting INFRAI_API_KEY, AUTH_API_ORIGIN, CONSENT_USER_ID, and CONSENT_CATEGORY. Set the origin to the provider's HTTPS API origin without a trailing slash or version path; use the authenticated resident identifier and your actual consent category. This diagnostic prints the response for inspection and deliberately does not authorize an export merely because a request succeeded.
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func required(name string) string {
v := os.Getenv(name)
if v == "" {
panic("missing environment variable: " + name)
}
return v
}
func run() error {
key := required("INFRAI_API_KEY")
origin := required("AUTH_API_ORIGIN")
u, err := url.Parse(origin)
if err != nil || u.Scheme != "https" || u.Host == "" ||
u.User != nil || u.Path != "" || u.RawQuery != "" || u.Fragment != "" {
return fmt.Errorf("AUTH_API_ORIGIN must be an HTTPS origin")
}
path := strings.NewReplacer(
"{user_id}", url.PathEscape(required("CONSENT_USER_ID")),
"{category}", url.PathEscape(required("CONSENT_CATEGORY")),
).Replace("/v1/auth/consent/check/{user_id}/{category}")
endpoint := origin + path
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
client := &http.Client{
Timeout: 10 * time.Second,
CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
},
}
for attempt := 0; attempt < 3; attempt++ {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
body, readErr := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
resp.Body.Close()
if readErr != nil {
return readErr
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
delay := time.Second * time.Duration(1<<attempt)
retry := resp.Header.Get("Retry-After")
if seconds, err := strconv.ParseInt(retry, 10, 32); err == nil && seconds >= 0 {
if wait := time.Duration(seconds) * time.Second; wait > delay {
delay = wait
}
} else if date, err := http.ParseTime(retry); err == nil {
if wait := time.Until(date); wait > delay {
delay = wait
}
}
timer := time.NewTimer(delay)
select {
case <-ctx.Done():
timer.Stop()
return ctx.Err()
case <-timer.C:
}
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("consent check returned %d: %s", resp.StatusCode, body)
}
fmt.Println(string(body))
return nil
}
return fmt.Errorf("retry budget exhausted")
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
The acceptance criterion for the integration is a sequence of decisions: initially allow; after withdrawal deny; after recovery without a new grant deny; after a new grant still deny the revoked session; allow only the recovered session with current consent. These are test expectations, not reported live results. Inspect the documented response contract before mapping it to that decision: HTTP success means the check completed, not that consent exists.
The example's limitations matter. It doesn't implement refresh-token rotation, a recovery workflow, or an atomic export transaction. Production integration needs an authoritative decision source, synchronization appropriate to that source, authenticated recovery transitions, and an explicit policy for the interval between admission and data release. Treat those as implementation requirements rather than extrapolating a distributed guarantee from a small program.
Bound failures and decide when this advice applies
Step 4 is to allocate capacity to the checks the design actually performs. If each export has one request admission and one worker admission, a planning workload of 60 exports per minute implies 120 consent checks per minute before retries, downloads, or additional release checks. Those are hypothetical inputs, not benchmark results. Queueing can smooth export execution while moving check traffic into bursts, so size and observe the worker path too.
On a consent-check timeout, do not manufacture a grant from the session. Defer or deny the protected export under a documented policy, surface a useful error, and track dependency failures separately from explicit withdrawals. That choice sacrifices some export availability to preserve the revocation rule; the SLO and on-call runbook should acknowledge the sacrifice. Recovery screens also need to distinguish “your session is invalid” from “this export lacks current consent,” without suggesting that signing in again reverses withdrawal.
A seconds-long cache is a bounded concession. Write down its maximum age and the resulting withdrawal exposure; invalidate it on a known withdrawal where possible, but do not make delivery of that invalidation the sole correctness mechanism. A session-long cache has the wrong lifetime for this job.
This advice applies when consent is the authorization condition for the export. It does not decide retention duties, erase a file already released, or prove a legal compliance claim. For the property portal's recovery path, the release criterion is concrete: the stolen session remains denied, the recovered session receives no inherited export grant, and every new protected admission consults current consent.
Sources
References for the security boundaries and the product-specific review questions:
Top comments (0)