The OIDC plugin fails when we send the bearer token in a custom header, how do we get the plugin to find the token? Custom header example: jefftoken-xyz: Bearer XXXXXXXXXX
Using OIDC with a custom bearer token header
How do I get the OIDC plugin to find a bearer token sent in a custom header?
The OIDC plugin only reads the token from the Authorization header.
Use the serverless pre-function plugin to copy the value from your custom header into Authorization before the OIDC plugin runs.
Problem
Solution
Use the serverless pre-function plugin to change the header from jefftoken-xyz to Authorization.
-
Create some custom lua code to add a new header using the value from
jefftoken-xyzand save the file ascustom-auth.lua:local authhead = kong.request.get_header("jefftoken-xyz") kong.service.request.set_header("authorization", authhead)Optionally, you can also delete the original header with the following additional line depending on whether the upstream still needs the original value:
kong.service.request.clear_header("jefftoken-xyz") -
Add a pre-function plugin with config file
custom-auth.lua(make sure your working directory has thecustom-auth.luafile in it):curl -i -X POST http://localhost:8001/services/<your service name>/plugins \ -H "kong-admin-token: <your admin token value>" \ -F "name=pre-function" \ -F "config.access[1]=@custom-auth.lua" \
The OIDC plugin will now find the bearer token in the Authorization header.