基本身份验证:supergaent + OSX失败,superagent + Redhat上成功,Postman + OSX上成功, [英] Basic authentication : failure supergaent+OSX , success on superagent+Redhat , success on Postman+OSX,
问题描述
使用POSTMAN,一切都很好:
Using POSTMAN , everything is fine :
我将相同的标头,参数,...传递给superagent,如下所示:
I pass the same headers,params,... to superagent as following :
const superagent = require('superagent');
const grab = require('ps-grab');
superagent.get('https://x.rathath.net/issue_statuses.json')
.set({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
.auth(grab('--user'),grab('--password'))
.send({})
.end((error,response)=>{
console.log(response.text);
});
但是失败了!
我对以下内容有疑问:superagent + Authorization Header + OSX ..我的意思是这三者的兼容性.
I have a doubt in : superagent+Authorization Header+ OSX .. I mean compatibility of those three .
实际上,我在Redhat机器上运行了相同的javascript代码段,并且运行正常.
Indeed, I run the same javascript snippet on Redhat machine and it works fine.
推荐答案
区别在于您可能正在调用另一个域而不是js应用程序正在运行的域.这称为CORS.当您这样做时,结合身份验证,服务器需要返回CORS标头,说:
The difference is that you are probably making a call to another domain than where your js app is running. This is called CORS. When you do that, combined with Authentication, the server needs to return CORS headers, saying:
access-control-allow-credentials: true
access-control-allow-origin: your-app-domain.here
两个陷阱:
- 在您的超级代理调用中忘记了.withCredentials().这不仅适用于Cookie,还适用于身份验证.
- 服务器返回*而不是您的域,但这与身份验证结合使用是不允许的.
这篇关于基本身份验证:supergaent + OSX失败,superagent + Redhat上成功,Postman + OSX上成功,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!