Can an Apigee proxy look up a client_id from a custom attribute on the app?

I know that you can use the VerifyAPIKey policy to look up the app custom attribute data of the provided client_id you are verifying.

But is there a way to cause Apigee to look up the client_id which has an app custom attribute that matches a provided attribute name and provided value?

For example:

Lets say I have an app with a credential with a 'client_id' of '12345'. Lets say I add an app custom attribute to it, called 'legacy_client_id', and give it a value of '98765'.

In my flow I would like to provide to some policy an attribute name of 'legacy_client_id' and an attribute value of '98765' from the request, and have the policy populate a flow variable called something like 'policy_name.client_id' which contains the value '12345'.

Is this possible with Apigee?

Solved Solved
0 1 366
1 ACCEPTED SOLUTION

No, what you describe is not possible, not directly.

But, you could sort-of get there, you could do it indirectly, if you denormalize the data and store the lookup table you want, elsewhere. For example, suppose you have these data:

client idlegacy id
1234598765
2468011223
1357977373

As you point out, VerifyApiKey will retrieve the legacy id "implicitly".

If you want to reverse the direction of the lookup, then you'd need to produce a data table that CAN support that lookup. This could be a KVM, or it could be a JSON settings file. To produce that table, you would need to scan all apps in the system and produce the lookup table.

In JavaScript with a JSON formatted lookup table, it would look like this:


var mappings = {
  "12345" : "98765",
  "24680" : "11223",
  "13579" : "77373"
};


function findClientId(legacyid) {
  var keyfound = Object.keys(mappings).find(function(key) {
        return mappings[key] == legacyid;
      });
  return keyfound; // maybe null
}


var found1 = findClientId("98765"); // "12345"
var found2 = findClientId("55512"); // null


But it would be up to you to produce the mappings table, and to keep it synchronized with the data in the custom attributes.

Obviously you wouldn't want the JSOn to be hardcoded into your JavaScript execution. So you could use the IncludeURL element to include it separately.

mappings.js:

var mappings = {
  "12345" : "98765",
  "24680" : "11223",
  "13579" : "77373"
};


lookupLegacyId.js

function findClientId(legacyid) {
  var keyfound = Object.keys(mappings).find(function(key) {
        return mappings[key] == legacyid;
      });
  return keyfound; // maybe null
}


var found1 = findClientId("98765"); // "12345"

JS policy:

<Javascript name='JS-Lookup' >
  <IncludeURL>jsc://mappings.js</IncludeURL>
  <ResourceURL>jsc://lookupLegacyId.js</ResourceURL>
</Javascript>

Or, if you get really fancy you could have that mapping table be delivered by a remote service. And use ServiceCallout or the httpClient in the JS client to retrieve it.

View solution in original post

1 REPLY 1

No, what you describe is not possible, not directly.

But, you could sort-of get there, you could do it indirectly, if you denormalize the data and store the lookup table you want, elsewhere. For example, suppose you have these data:

client idlegacy id
1234598765
2468011223
1357977373

As you point out, VerifyApiKey will retrieve the legacy id "implicitly".

If you want to reverse the direction of the lookup, then you'd need to produce a data table that CAN support that lookup. This could be a KVM, or it could be a JSON settings file. To produce that table, you would need to scan all apps in the system and produce the lookup table.

In JavaScript with a JSON formatted lookup table, it would look like this:


var mappings = {
  "12345" : "98765",
  "24680" : "11223",
  "13579" : "77373"
};


function findClientId(legacyid) {
  var keyfound = Object.keys(mappings).find(function(key) {
        return mappings[key] == legacyid;
      });
  return keyfound; // maybe null
}


var found1 = findClientId("98765"); // "12345"
var found2 = findClientId("55512"); // null


But it would be up to you to produce the mappings table, and to keep it synchronized with the data in the custom attributes.

Obviously you wouldn't want the JSOn to be hardcoded into your JavaScript execution. So you could use the IncludeURL element to include it separately.

mappings.js:

var mappings = {
  "12345" : "98765",
  "24680" : "11223",
  "13579" : "77373"
};


lookupLegacyId.js

function findClientId(legacyid) {
  var keyfound = Object.keys(mappings).find(function(key) {
        return mappings[key] == legacyid;
      });
  return keyfound; // maybe null
}


var found1 = findClientId("98765"); // "12345"

JS policy:

<Javascript name='JS-Lookup' >
  <IncludeURL>jsc://mappings.js</IncludeURL>
  <ResourceURL>jsc://lookupLegacyId.js</ResourceURL>
</Javascript>

Or, if you get really fancy you could have that mapping table be delivered by a remote service. And use ServiceCallout or the httpClient in the JS client to retrieve it.