api-umbrella icon indicating copy to clipboard operation
api-umbrella copied to clipboard

cannot find how to use template for request header

Open lucatoni opened this issue 6 years ago • 1 comments

I tried to pass X-Api-Roles to the backend API (couchdb), but I could not figure out how to use a template to achieve this. In "Global Request" settings I entered:

X-Auth-CouchDB-Token: (mysecretttoken)
X-Auth-CouchDB-UserName: apiumbrella
X-Auth-CouchDB-Roles: {{X-Api-Roles}}
Content-Type: application/json; charset=utf-8
Accept: application/json

The value of X-Api-Roles is passed to the backend, but I would like to pass it as X-Auth-CouchDB-Roles. How can I achieve this?

tcpdump snippet showing request from API umbrella to API backend:

        0x0290:  330d 0a58 2d41 7069 2d55 7365 722d 4964  3..X-Api-User-Id
        0x02a0:  3a20 6531 6665 6632 3230 2d30 6166 642d  :.XXXXXXX-0afd-
        0x02b0:  3439 3062 2d61 3833 312d 3461 6639 6232  490b-a831-4af9b2
        0x02c0:  6630 3234 3963 0d0a 582d 4170 692d 526f  f0249c..X-Api-Ro
        0x02d0:  6c65 733a 2063 6f75 6368 2d62 652d 7465  les:.couch-xx-yy
        0x02e0:  616d 2d75 7365 7273 0d0a 582d 4175 7468  yy-users..X-Auth
        0x02f0:  2d43 6f75 6368 4442 2d54 6f6b 656e 3a20  -CouchDB-Token:.
        0x0300:  3533 3464 3132 3465 3366 6230 3063 6537  xxxxxxxxx
        0x0310:  3761 3139 6230 3236 3963 3166 6664 6131  7a19b0269c1ffda1
        0x0320:  3130 6661 6461 3136 0d0a 582d 4175 7468  10fada16..X-Auth
        0x0330:  2d43 6f75 6368 4442 2d55 7365 724e 616d  -CouchDB-UserNam
        0x0340:  653a 2061 7069 756d 6272 656c 6c61 0d0a  e:.apiumbrella..

lucatoni avatar Jul 06 '19 16:07 lucatoni

Figured it out after looking at this pull request.

This did the trick: In "API Backends" under "Global Request Settings / Set Request Headers" I had to add

X-Auth-CouchDB-Roles: {{headers.x-api-roles}}

So, while my couchdb backend API is always accessed with one and the same proxy user (I named it apiumbrella, suprisingly), I can pass in roles specific to the API-key / API-user.

Is there a list of all headers supporting template-based rewriting, or can I just use any header translated to lower case?

lucatoni avatar Jul 07 '19 16:07 lucatoni