Kong/kong-python-pdk

Question: looking up a consumer by custom_id

Closed this issue · 1 comments

I'm working on a Python plugin that will validate an OAuth access token and, if valid, want to then use information from the token to set the Kong consumer context of the request. Our standard for creating consumers is:

  • username: application name from the IdP
  • custom_id: the client ID for the app from the IdP

Access tokens generated by the IdP will include the app's client ID in the cid claim, and this is what I have in hand to try to match the consumer. In an earlier Lua plugin, I first used the PDK method kong.db.consumers:select_by_username() to get the consumer object's internal ID, and if that didn't match, I used kong.db.consumers:select_by_custom_id(); once I had the ID, then I set the consumer context with kong.client.authenticate().

However, it looks like the kong.db interface doesn't exist in the Python PDK, and the kong.client.load_consumer() method only supports searching by the username attribute. Is there any option for finding the consumer by the custom_id with the Python PDK?

Closing this because investigation seems to indicate that you cannot find a consumer object by the custom_id attribute with the PDK (also seems to be the case for the Golang and JavaScript PDKs). I ended up having to call out to the Kong admin API directly from the plugin to accomplish this. Not at all ideal, but it worked.