Basic authentication : failure supergaent+OSX , success on superagent+Redhat , success on Postman+OSX,

落爺英雄遲暮 提交于 2019-12-20 03:13:31

问题


Using POSTMAN , everything is fine :

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);
    });

However it is failed !

I have a doubt in : superagent+Authorization Header+ OSX .. I mean compatibility of those three .

Indeed, I run the same javascript snippet on Redhat machine and it works fine.


回答1:


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

Two pitfalls:

  • Forgetting .withCredentials() in your superagent call. This is not just for cookies but also for Authentication.
  • The server returning * instead of your domain, but that is not allowed in combination with Authentication.


来源:https://stackoverflow.com/questions/40064018/basic-authentication-failure-supergaentosx-success-on-superagentredhat-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!