[英]Access_token works in localhost not in server
I am using the following code in my application to check if some headers are provided .The code works fine in localhost but not when the application is deployed to server . 我在应用程序中使用以下代码来检查是否提供了一些标头。该代码在localhost中工作正常,但在将应用程序部署到server时无法正常工作。 Basically I am trying to check if headers are present in the request.
基本上我正在尝试检查请求中是否存在标头。 On the server , I keep getting invalid request .
在服务器上,我一直收到无效请求。 When I pass accesstoken instead of access_token , the request goes through successfully .
当我通过accesstoken而不是access_token时,请求成功通过。 So by changing
if ((request.headers.access_token && request.headers.refresh_token && request.headers.id_token) || request.headers.token)
to 因此,通过将
if ((request.headers.access_token && request.headers.refresh_token && request.headers.id_token) || request.headers.token)
更改为
The code works , my question is why is this happening 代码有效,我的问题是为什么会这样
const Hapi = require('hapi');
const Path = require('path');
const axios = require('axios');
var tokenValidation = function (request, reply) {
if ((request.headers.access_token && request.headers.refresh_token && request.headers.id_token) || request.headers.token) {
if (request.headers.access_token != undefined) {
//do something
}
else {
return reply.continue();
}
} else
return reply.continue();
}
else {
var err = Boom.badRequest(‘Invalid request.');
reply(err);
}
}
server.ext('onRequest', tokenValidation);
Missing (disappearing) HTTP Headers If you do not explicitly set underscores_in_headers on;, NGINX will silently drop HTTP headers with underscores (which are perfectly valid according to the HTTP standard). 缺少(消失)的HTTP标头如果未明确将underscores_in_headers设置为on,NGINX将以带下划线的方式静默丢弃HTTP标头(根据HTTP标准,这是完全有效的)。 This is done in order to prevent ambiguities when mapping headers to CGI variables as both dashes and underscores are mapped to underscores during that process.
这样做是为了防止在将标头映射到CGI变量时混淆,因为在此过程中,破折号和下划线都映射到了下划线。
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#missing--28disappearing-29-http-headers https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#missing--28disappearing-29-http-headers
We have to explicitly underscores_in_headers on in NGINX , else they will be ignored 我们必须在NGINX中显式强调underscores_in_headers,否则它们将被忽略
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.