CORS settings of OIDC 401 unauthorized response

I am using TYK with OIDC and my backend natively supports CORS that’s why I have enabled CORS.options_passthrough. Application works fine normally if JWT is valid and I don’t get any CORS errors. But problem is after JWT expiry TYK 401 unauthorized response doesn’t contain CORS headers because of course it doesn’t proxy that request to backend. My question is can we configure headers injection or CORS only in that specific case? I know that messages can be configures using Tyk Gateway Configuration Options but can we fully customize OIDC error response headers using configurations?
My API definition file is:

{
    "name":"backend - OIDC",
    "api_id":"4",
    "org_id":"1",
    "version_data": {
      "not_versioned": true,
      "versions": {
        "Default": {
          "name": "Default",
          "use_extended_paths": true
        }
      }
    },
    "use_openid": true,
    "openid_options": {
       "providers": [
          {
             "issuer": "https://auth.somedomain.me/auth/realms/somerealm",
             "client_ids": {
                "dHlrLXRlc3Q=": "admin"
             }
          }
       ],
       "segregate_by_client": false
    },
    "CORS": {
      "options_passthrough": true,
      "debug": true
    },
    "proxy":{
       "listen_path":"/backend-oidc/",
       "target_url": "http://backend",
       "strip_listen_path":true
    },
    "active":true
 }
 

Related:

Hi @armujahid, thanks for sharing the relevant links. I will attempt to answer your questions below

My question is can we configure headers injection or CORS only in that specific case?

  1. I guess you could with custom plugins but I haven’t tried. If it is something you have tried, can you let us know how it went.

I know that messages can be configures using Tyk Gateway Configuration Options but can we fully customize OIDC error response headers using configurations?

  1. From what I can see in the source I think not.

I did want to ask does any of the available options as mentioned in the thread and highlighted below :

  • Using Nginx server in front of Tyk Gateway

  • Using a keyless API in front of your OIDC auth API

not work for you and why?

For now I am using a keyless API in front of OIDC auth API and that solution is working fine so far.