Skip to content

lua-nginx-module #4485

@roldanarvin8-ship-it

Description

@roldanarvin8-ship-it

> Hello

Yes I was able to get it working using lua-nginx-module to rewrite the request.

If your Postgrest API server is on http://localhost:3000 and your Nginx Proxy is on http://localhost:3001, you can use this nginx proxy config and make request to your nginx proxy with a cookie access_token that contains the jwt (it rewrites the headers to include a Authorization: Bearer <jwt> header:


server {

  listen  0.0.0.0:3001;



  location / {

     rewrite_by_lua_block {

       local cookie_value = ngx.req.get_headers()["Cookie"]

       if cookie_value ~= nil then

         local jwt = cookie_value:match("access_token=([^ ]+)")

         ngx.req.set_header("Authorization", "Bearer " .. jwt)

       end

       ngx.req.clear_header("Cookie")

     }

     proxy_pass http://0.0.0.0:3000;

  }

}

Actual request (to nginx proxy by the client):


GET  HTTP/1.1

Host: localhost:3001

Cookie: access_token=mah.osum.token

Request relayed to Postgrest:


GET  HTTP/1.1

Host: localhost:3000

Authorization: Bearer mah.osum.token

Note that the regex used to extract the access_token only works correctly when there is a single cookie.

Originally posted by @tocttou in #773

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions