Identity Cloud

Authorize endpoint data provider plugin

Use this plugin to configure the OAuth 2.0 provider to return additional data from an authorization request, such as data from the user’s session or from an external service.

To view a sample script, including the available script properties, see oauth2-authorize-endpoint-data-provider.js.

Example authorize endpoint data provider plugin

Complete the following steps to implement an authorize endpoint data provider script that returns custom user session data:

Prepare the authorize endpoint data provider script

This task decribes how to create a script to retrieve additional fields.

  1. In the AM admin UI, go to Realms > Realm Name > Scripts, and click New Script.

  2. Enter a unique name for your script, select OAuth2 Authorize Endpoint Data Provider from the Script Type drop-down list, and click Create.

  3. Copy the oauth2-authorize-endpoint-data-provider.js script and paste in the Script field.

    • Enable the script by removing, or commenting out as seen in this example, the following block comments surrounding the function, on lines 40 and 90:

      // /* EXAMPLE
      // */
    • For the purposes of this simple test, comment out the call to add data from a third-party service:

  4. Save your changes.

The template authorize endpoint data provider script is now amended to return a static key/value pair, "hello": "world", and to get the user’s IP address from the session data.

Configure AM to use the authorize endpoint data provider script

Perform this task to set up an OAuth2 provider to use the authorize endpoint data provider script.

  1. Log in to the AM admin UI as an administrator.

  2. Configure the provider to ensure the following properties are set:

    • Authorize Endpoint Data Provider Plugin Type to SCRIPTED.

    • Authorize Endpoint Data Provider Script to the name of the script you created.

  3. Save your changes.

Create an OAuth2 client for authorization

Create an OAuth 2.0 client to use in the authorization request.

  1. In the AM admin UI, go to Realms > Realm Name > Applications > OAuth 2.0 > Clients, and click Add Client.

  2. Enter the following values:

    • Client ID: myClient

    • Client secret: forgerock

    • Redirection URIs:

    • Scope(s): access|Access to your data

  3. Click Create.

AM is now prepared for you to perform an OAuth2 authorization request to try the sample plugin.

Try the sample authorize endpoint data provider plugin

  1. Log in to AM as the demo user, for example:

    $ curl \
    -i \
    --request POST \
    --header "Content-Type: application/json" \
    --header "X-OpenAM-Username: demo" \
    --header "X-OpenAM-Password: Secret12!" \
    --header "Accept-API-Version: resource=2.0, protocol=1.0" \

    Note the SSO token value returned as tokenId in the output.

  2. Invoke the authorization server’s /oauth2/authorize endpoint specifying the SSO token value in a cookie, and the following parameters:

    • client_id=myClient

    • response_type=code

    • redirect_uri=

    • decision=allow

    • csrf=SSO-token

    For example:

    $ curl --dump-header - \
    --request POST \
    --Cookie "iPlanetDirectoryPro=AQIC5wM…​TU3OQ*" \
    --data "scope=access" \
    --data "response_type=code" \
    --data "client_id=myClient" \
    --data "csrf=AQIC5wM…​TU3OQ*" \
    --data "redirect_uri=" \
    --data "state=abc123" \
    --data "decision=allow" \

    If the authorization server is able to authenticate the user and the client, it returns a successful HTTP 302 response, for example:

    HTTP/1.1 302 Found
    Server: Apache-Coyote/1.1
    X-Frame-Options: SAMEORIGIN
    Pragma: no-cache
    Cache-Control: no-store
    Date: Mon, 30 Jul 2018 11:42:37 GMT
    Accept-Ranges: bytes
    Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
    Content-Length: 0

    As seen in the example output, the parameters injected by the authorize endpoint data provider script, ipAddress= and hello=world, are both appended to the redirect URL.

OAuth 2.0 authorize endpoint data provider scripting API

The following properties are available to authorize endpoint data provider scripts, in addition to the common OAuth 2.0 properties.

Show script properties

Contains a representation of the user’s session object if the request contained a session cookie.

Copyright © 2010-2022 ForgeRock, all rights reserved.