Hi chris,
It returns the user_name what I expected. But I want to pass that value to the another location block called /api. But tried both $remote_user and "set $user_name" variable to pass the value it is not working. Please check the below configuration and tell me your suggestions. Thank you.
```
server {
listen 443;
server_name servername.com;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/cert.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location / {
set $user_name '';
access_by_lua_block {
local opts = {
redirect_uri_path = "/secret/redirect",
discovery = "https://hostname/.well-known/openid-configuration",
client_id = "@!22A9 - my client id is here",
client_secret = "password",
scope = "openid user_name profile",
redirect_uri_scheme = "https",
token_endpoint_auth_method = "client_secret_basic",
ssl_verify = "no",
timeout = 7200,
}
-- call authenticate for OpenID Connect user authentication
local res, err = require("resty.openidc").authenticate(opts)
if err then
ngx.status = 500
ngx.say(err)
ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
ngx.var.user_name = res.user.user_name
#ngx.var.remote_user = res.user.user_name
}
}
location /api/ {
proxy_pass http://java-servie:8800/;
proxy_set_header remote_user $user_name;
proxy_set_header X-Forwarded-Proto "https";
}
}
```