简体   繁体   English

使用快递的 Cors 的基本身份验证

[英]Basic auth with Cors using express

so im trying to integrate an ionic app with the current working sytem.所以我试图将离子应用程序与当前的工作系统集成。 I have an api handler to resolve cors/ cross origin with express.我有一个 api 处理程序来使用 express 解决 cors/cross origin。

currently my headers api are:目前我的标题 api 是:

  app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "http://localhost:4200");
  res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
  res.header(
    "Access-Control-Allow-Headers",
    "Authorization, Origin, X-Requested-With, Content-Type, Accept"
  );
  res.header("Access-Control-Allow-Credentials", "true");
  res.header('Authorization', auth);
  next();
});

it reaches this url and the user is prompted like this, this is an hta access file behind the scenes User Prompt它到达这个 url 并提示用户是这样的,这是幕后的 hta 访问文件用户提示

I think i need to have my api send the header which happens to be basic auth:我想我需要让我的 api 发送 header 这恰好是基本身份验证:

var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');

Now my question is how do i handle this prompt/ log in before the get?现在我的问题是如何在获取之前处理此提示/登录?

I tried passing the Auth in the res.header which sends an outgoing header object that looks like this Header object I tried passing the Auth in the res.header which sends an outgoing header object that looks like this Header object

so im trying to integrate an ionic app with the current working sytem.所以我试图将离子应用程序与当前的工作系统集成。 I have an api handler to resolve cors/ cross origin with express.我有一个 api 处理程序来使用 express 解决 cors/cross origin。

currently my headers api are:目前我的标题 api 是:

  app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "http://localhost:4200");
  res.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
  res.header(
    "Access-Control-Allow-Headers",
    "Authorization, Origin, X-Requested-With, Content-Type, Accept"
  );
  res.header("Access-Control-Allow-Credentials", "true");
  res.header('Authorization', auth);
  next();
});

it reaches this url and the user is prompted like this, this is an hta access file behind the scenes User Prompt它到达这个 url 并提示用户是这样的,这是幕后的 hta 访问文件用户提示

I think i need to have my api send the header which happens to be basic auth:我想我需要让我的 api 发送 header 这恰好是基本身份验证:

var auth = 'Basic ' + Buffer.from(username + ':' + password).toString('base64');

Now my question is how do i handle this prompt/ log in before the get?现在我的问题是如何在获取之前处理此提示/登录?

I tried passing the Auth in the res.header which sends an outgoing header object that looks like this Header object I tried passing the Auth in the res.header which sends an outgoing header object that looks like this Header object

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM