I'm trying to authenticate a user then allow him to download S3 files via ngx proxy services. The file download works if I don't try to authenticate. I'm not able to proxy over to the download location because of headers, it seems.
The authentication portion:
location ~* ^/(.*) {
content_by_lua
'
local cjson = require "cjson"
local bcrypt = require "bcrypt"
if ngx.var.remote_user and ngx.var.remote_passwd then
local host = ngx.req.set_header("Host","localhost:5984")
ngx.req.set_header("Content-Type","application/json")
local res = ngx.location.capture("/couch_session",{method=ngx.HTTP_POST,body=cjson.encode({name=ngx.var.remote_user,password=ngx.var.remote_passwd})});
if res.status == 200 then
I would like to use this section to validate users, expire their authentication(so they re-login), and to proxy over to the download location. I don't know how)
end
else
ngx.header.WWW_authenticate = [[Basic realm="www.example.com"]]
ngx.exit(401)
end
The two other locations, one for couchDB to authenticate, and the other is download (which works if on its own):
location /couch_session{
proxy_pass http://localhost:5984/_session;
}
location /download {
proxy_pass_request_headers off;
set $key $1;
set_secure_random_alphanum $prefix 64;
set_by_lua $date "return ngx.cookie_time(ngx.time())";
set_sha1 $datesha $date;
set $bucket ....
';
}
Thanks.