I'm currently facing an authentication issue while deploying my Socket.IO application with Nginx as a proxy. Locally, everything is working fine, and I can authenticate socket connections using the acces_token header. However, after deployment, the tokens are not being recognized on the backend.
Setup: I have a frontend and backend application where I use Socket.IO for real-time communication. In the frontend, I send an access_token header to authenticate the socket connection.
Issue: When deploying the application and using Nginx as a proxy, the backend no longer recognizes the access_token header. This results in failed socket authentication.
Local Environment (Working): in frontend i am passing like this
in the backend i am getting like this,
handshake: {
headers: {
host: 'localhost:3000',
connection: 'keep-alive',
'sec-ch-ua': '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
accept: '*/*',
dnt: '1',
acces_token: 'mytokenvalue',
'sec-ch-ua-mobile': '?0',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
referer: 'http://localhost:3000/admin',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7'
},
here i am able to get acces_token
Deployed Environment (Not Working):
[here the token is not receving] (https://i.sstatic.net/qiwLe.png)
so we assume that its nginx configuration issue
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header acces_token "MyToken";
spec:
when we adding this static value (MyToken) , its getting ...
but we need this value from request we try to add like this ,
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
annotations:
nginx.ingress.kubernetes.io/configuration-snippet: |
proxy_set_header acces_token "$http_x_acces_token";
spec:
# ... other Ingress specifications
but not working
I would greatly appreciate any insights or suggestions to help me resolve this authentication problem. Thank you for your time and assistance.
Nginx should pass all headers if 'proxy_pass_request_headers' is on, but headers with underscores are by default ignored, see 'ignore_invalid_headers' and 'underscores_in_headers' setting.