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

前端 未结 1 1067
夕颜
夕颜 2021-01-22 02:08

Using POSTMAN , everything is fine :

I pass the same headers,params,... to superagent as following :

const superagent = require(\'superagent\');
const          


        
相关标签:
1条回答
  • 2021-01-22 02:41

    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.
    0 讨论(0)
提交回复
热议问题