Step 3 — Handling the redirect

Receive the user back from Hub and check the response is genuine.

When the user finishes at Hub — or cancels, or fails — Hub sends them back to your redirect_uri.

This page covers what arrives and what to do with it.

Success

The user's browser makes a normal GET request to your redirect_uri, with these query parameters:

https://acme-widgets.example.com/callback
  ?code=5GT81abUDETEOpVegWBZ78AejqElS-atMzTNF_7UQYQ.IfKMxHcxM5PdoDtQyNhXl5jb8uS5lxs1xc-hQHRcR8Q
  &scope=openid+onlyVme_scope
  &state=5de789881cc944a78e9c1c9d947f7867
ParameterWhat it is
codeA one-time authorization code. Swap it for an access token in Step 4.
scopeThe scope you requested.
stateThe exact value you sent in Step 2.

What to do, in order

1. Check state first.

Look up the returned state against the user session you stored it in. If there's no match, discard the request.

session = sessions.get(request.args["state"])
if session is None:
    abort(400)   # not a request we started
const session = sessions.get(req.query.state);
if (!session) {
  return res.sendStatus(400); // not a request we started
}
var session = sessions.get(ctx.queryParam("state"));
if (session == null) {
    ctx.status(400); // not a request we started
    return;
}
if (!sessions.TryGetValue(ctx.Request.Query["state"].ToString(), out var session))
    return Results.BadRequest(); // not a request we started
📘

Why check state? It's a security best practice. A match confirms the response belongs to the user in front of you and comes from a verification you started, so a code from another session can't be slipped in. Checking it first, every time, keeps your integration secure.

2. Use state once. Delete it after a successful match so the same response can't be replayed.

3. Check for an error. If error is present, there's no code. Go to the error section below.

4. Exchange the code. See Step 4.

🚧

The code can only be used once, and it expires 10 minutes after it's issued. Exchange it as soon as you receive it.

Errors

When something goes wrong, you get an error instead of a code:

https://acme-widgets.example.com/callback
  ?error=access_denied
  &error_description=User+cancelled
  &state=5de789881cc944a78e9c1c9d947f7867
  &locale=en-CA
ParameterWhat it is
errorThe OAuth error code. Usually access_denied.
error_descriptionWhat went wrong. Always returned. Branch on this, not error.
stateStill returned — still check it.
localeThe language the user was using.
🚧

error_description is URL-encoded in the URL, so User+cancelled means User cancelled. Most web frameworks decode query parameters for you, as in the examples below. If you read the raw URL yourself, decode it before comparing.

📘

Your app shows the error, not Hub. When a verification ends without success, Hub doesn't show the user an error page. It redirects them to your redirect_uri with the error in the query string, which the user never sees. What happens next is up to you: build the page or journey the user lands on, such as a retry option, an alternative path, or how to get help. See Not every error means failure for suggested handling.

The exception is a request Hub can't safely redirect, such as one with an unregistered redirect_uri. Hub shows its own error page instead.

Example: the user cancels

The URL above is what arrives when a user taps Cancel on a Hub screen. They're now on your callback page, and they only know what happened if you tell them.

A good response:

  1. Check state as usual.
  2. Recognise the cancellation from error_description.
  3. Show a friendly page, not an error screen. Say that nothing was shared, and offer a way forward.
d = request.args["error_description"]

if d == "User cancelled":
    return redirect("/verification-cancelled")
const d = req.query.error_description;

if (d === "User cancelled") {
  return res.redirect("/verification-cancelled");
}
String d = ctx.queryParam("error_description");

if ("User cancelled".equals(d)) {
    ctx.redirect("/verification-cancelled");
    return;
}
var d = ctx.Request.Query["error_description"].ToString();

if (d == "User cancelled")
    return Results.Redirect("/verification-cancelled");

What the user might see:

Verification cancelled

No details were shared with Acme Widgets.

[Try again] [Verify another way]

Try again starts a fresh verification from Step 2, with a new state.

Values you'll see

errorerror_descriptionMeaning
access_deniedUser cancelledThe user cancelled on a Hub screen
session_expiredThe session has expiredThe user ran out of time
access_deniedService errorThe verification failed
access_deniedDocument RThe document was rejected
access_deniedDocument SThe document was suspected
🚧

Timeouts use error=session_expired, not access_denied. Handle it explicitly or it falls through your catch-all.

Don't match against a fixed list

These are the common values, not all of them. Hub assembles error_description when a verification fails, so other values exist — Document idv_expired, Document error, Verified.Me completed and Document R, and more.

Match on how the value starts or what it contains:

d = request.args["error_description"]

if "could not be matched" in d:
    handle_match_failure(d)
elif d.startswith("Document "):
    handle_document_failure(d)
elif d.startswith("Verified.Me "):
    handle_bank_failure(d)
else:
    handle_generic_failure(d)
const d = req.query.error_description;

if (d.includes("could not be matched")) {
  handleMatchFailure(d);
} else if (d.startsWith("Document ")) {
  handleDocumentFailure(d);
} else if (d.startsWith("Verified.Me ")) {
  handleBankFailure(d);
} else {
  handleGenericFailure(d);
}
String d = ctx.queryParam("error_description");

if (d.contains("could not be matched")) {
    handleMatchFailure(d);
} else if (d.startsWith("Document ")) {
    handleDocumentFailure(d);
} else if (d.startsWith("Verified.Me ")) {
    handleBankFailure(d);
} else {
    handleGenericFailure(d);
}
var d = ctx.Request.Query["error_description"].ToString();

if (d.Contains("could not be matched"))
    HandleMatchFailure(d);
else if (d.StartsWith("Document "))
    HandleDocumentFailure(d);
else if (d.StartsWith("Verified.Me "))
    HandleBankFailure(d);
else
    HandleGenericFailure(d);

See Error reference for how the values are built.

If your client has detailed error reporting

A small number of clients are configured for detailed error reporting, an optional capability subject to commercial agreement. Most integrations are not, and don't need to be.

Those clients receive two additions: a correlation ID (cid) and a structured error_description using a parseable grammar.

?error=access_denied
&error_description=err%3Auser_cancelled%24details%3Acancelled_on_landing_page%24stage%3Asharing_init
&cid=e661b5a0-4f33-4738-b6a0-0274bb455370
&state=5de789881cc944a78e9c1c9d947f7867

Decoded, the description is key:value pairs joined by $:

err:user_cancelled$details:cancelled_on_landing_page$stage:sharing_init
📘

If you're not seeing a cid, that's expected — it isn't a misconfiguration. See How Hub reports errors.

Not every error means failure

Some are ordinary user behaviour and deserve a friendly retry, not an error screen:

SituationSuggested handling
User cancelledOffer to start again
Session timed outOffer to start again
Document rejected or suspectedDepends on your policy — retry, another way to verify, or decline
System errorRetry later

Common mistakes

ProblemCause
You can't tell which user a response belongs tostate wasn't stored against the session
invalid_grant at Step 4The code was already used, or more than 10 minutes passed before you exchanged it
error_description looks like gibberishIt's URL-encoded — decode it first
Every failure looks the sameYou're branching on error. Branch on error_description.

Next

Step 4 — Token exchange