Orchestration SDKs

Integrating RAR into a JavaScript app

PingOne Advanced Identity Cloud PingAM JavaScript

The Orchestration SDK for JavaScript provides typed support for Rich Authorization Requests (RAR, RFC 9396) by using the oidc-client package.

You describe what the user is approving with AuthorizationDetail objects, the SDK sends them as the authorization_details parameter, and the details the server granted are echoed back with the token.

This page shows you how to add RAR to an existing app that signs on with PingOne Advanced Identity Cloud or PingAM.

Requesting authorization details

The first step in implementing RAR is to describe the details of what the user should authorize, so the server can present them as a rich consent. To do this, create AuthorizationDetail objects:

Example AuthorizationDetail object describing a specific payment
const payment = {
    type: "payment_initiation",
    actions: ["initiate"],
    locations: ["https://example.com/payments"],
    additionalFields: {
        instructedAmount: { currency: "EUR", amount: "123.50" },
        creditorName: "Merchant A",
    },
};

The type field is required; locations, actions, datatypes, and privileges are the common optional fields defined by RFC 9396.

Type-specific fields such as instructedAmount go in additionalFields, whose entries are flattened onto the object before the request is sent. Add all other fields there too: AuthorizationDetail is a TypeScript interface, so unknown properties added at the top level of the object fail type checking.

After creating the authorization detail, you can provide it to the Orchestration SDK during either of the following actions:

Configuring the oidc module

Add an authorizationDetails property when configuring the oidc module.

The configured details apply to every authorization request the client makes:

const rarLoginClient = await oidc({
    config: {
        clientId: "6c7eb89a-66e9-ab12-cd34-eeaf795650b2",
        redirectUri: "https://localhost:8443/callback.html",
        scope: "openid",
        par: true,
        authorizationDetails: [payment],
        serverConfig: {
          wellknown: "https://auth.pingone.ca/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration",
        },
    },
});
Starting the OAuth 2.0 flow

Per-call details are the natural fit for transactions, because each payment is a new consent.

Pass authorizationDetails to authorize.url() or authorize.background(); the per-call details override the client configuration for that request:

const authorizeUrl = await rarLoginClient.authorize.url({
    authorizationDetails: [payment],
});

You can also pass per-call details to token.get() when you use its automatic token renewal, through its authorizeOptions property:

const tokens = await rarLoginClient.token.get({
    backgroundRenew: true,
    forceRenew: true,
    authorizeOptions: {
        authorizationDetails: [payment],
    },
});

Running RAR alongside an existing login

A RAR login usually happens after the user has already signed in, so the app holds two tokens: the original login token, and the token issued for the RAR transaction.

To prevent the RAR login from overwriting the tokens from the original sign-in, configure a separate client for RAR transactions, with its own storage name:

Example of keeping RAR tokens in separate storage (PingOne Advanced Identity Cloud)
// The original sign-in (Token A)
const oidcClient = await oidc({
    config: {
        clientId: "6c7eb89a-66e9-ab12-cd34-eeaf795650b2",
        redirectUri: "https://localhost:8443/callback.html",
        scope: "openid",
        serverConfig: {
          wellknown: "https://auth.pingone.ca/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration",
        },
    },
});

// The RAR transaction login (Token B), in its own storage.
// RAR needs a separate storage location so it does not override
// tokens stored from a user flow.
// Configure the client once, at app startup:
const rarLoginClient = await oidc({
    storage: {
        name: "rar-client",
    },
    config: {
        clientId: "6c7eb89a-66e9-ab12-cd34-eeaf795650b2",
        redirectUri: "https://localhost:8443/callback.html",
        scope: "openid",
        par: true,
        serverConfig: {
          wellknown: "https://auth.pingone.ca/3072206d-c6ce-ch15-m0nd-f87e972c7cc3/as/.well-known/openid-configuration",
        },
    },
});

// For each RAR transaction, build the authorizationDetail:
const payment = {
    type: "payment_initiation",
    actions: ["initiate"],
    locations: ["https://example.com/payments"],
    additionalFields: {
        instructedAmount: { currency: "EUR", amount: "123.50" },
        creditorName: "Merchant A",
    },
};

// Then authorize, passing the detail per call:
const authorizeUrl = await rarLoginClient.authorize.url({
    authorizationDetails: [payment],
});

Reading the granted details

The authorization server echoes the details it actually granted in the token response, and the oidc-client package places them on the token object. The SDK does not modify the access token itself.

The granted set can differ from the requested set, so check it rather than assuming:

Example reading the granted authorization_details from the token
const tokens = await oidcClient.token.get();

tokens.authorizationDetails?.forEach((detail) => {
    console.log(`Granted type: ${detail.type}`);
});

Understanding the limitations

RAR needs the user to approve the payment details on the Remote Consent Service consent page, so it only works with the redirect authorization flow, where the user visits that page in the browser.

The authorize.background() function attempts authorization in a hidden iframe with prompt=none, which never displays a consent page. If you pass authorizationDetails there and the server requires interaction, the initial attempt fails, but the SDK returns an AuthorizationError with a redirectUrl property. This URL is a fallback authorization request with prompt=none stripped, so you can redirect the user to it to display the consent page and approve the transaction:

const response = await rarLoginClient.authorize.background({
    authorizationDetails: [payment],
});

if ("error" in response && response.redirectUrl) {
    window.location.assign(response.redirectUrl);
}

Next steps