Pre-Processing Procedures

Pre-processing procedures are used to customize (add/read/modify/remove) the request parameters before processing.

This is currently supported only on Dynamic Client Registration endpoint. It can be used with both registration and management endpoints for dynamic clients.

Function

A pre-processing procedure has the following format.

Listing 250 Example of a pre-processing procedure that sets additional parameters before processing
1
2
3
4
5
6
7
8
function result(context) {
    var attributes = {
        client_name: "client-name-from-pre-processing-script",
        extra_attribute: "some-extra-attribute"
    }

    return attributes;
}

The context object has type DcrPreProcessingProcedureContext.

Return Value

The returned value should be a JavaScript map with the pre-processed attributes. This map will be merged with input request parameters for processing. The values returned by this procedure take precedence over the same parameters in original request, if present.

Important

This procedure also has the power to introduce parameters that are not permissible in the original request. For example, client-template values can be overridden by this procedure in case of templatized clients.

Examples

Setting extra parameters

Listing 251 Example of a pre-processing procedure that sets additional parameters before processing
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
function result(context) {
    var request = context.getRequest()
    var httpMethod = request.getMethod()

    var clientName = "client-name-from-" + httpMethod.toLowerCase()
    var attributes = {
        client_name: clientName
    }

    if (httpMethod === 'POST') {
        attributes.client_id = "client-id-set-from-pre-processing-script"
    } else if (httpMethod === 'GET') {
        attributes.extra_attribute = 'coming-from-get'
    } else if (httpMethod === 'PUT') {
        attributes.extra_update_attribute = 'coming-from-put'
        attributes.client_name = 'updated-by-put-pre-processing-script'
    } else if (httpMethod === 'DELETE' && request.getQueryParameter('client_extra_attribute') === 'do-not-delete-me') {
        throw "DELETE not allowed when client_extra_attribute = do-not-delete-me"
    }

    return attributes;
}

Introspecting a token

A script that introspects a token in the input and sets attributes.

Listing 252 Pre-processing procedure introspecting token
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function result(context) {
    var tokenFromRequestParameter = context.getRegistrationData().get("token_to_introspect")
    var introspectedToken = context.introspectToken(tokenFromRequestParameter)

    var attributes = {
        introspectedToken: introspectedToken
    }

    return attributes;
}