【问题标题】:Stormpath A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is truStormpath 当凭证标志为 tru 时,不能在“Access-Control-Allow-Origin”标头中使用通配符“*”
【发布时间】:2016-11-28 23:40:51
【问题描述】:

我正在使用 Stormpath,我想将我的 API 与客户端代码(Angular,使用 Stormpath 的 angular-sdk)分开。这意味着 API 将位于与客户端不同的子域上。一旦我这样做了,我就遇到了错误;

A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true

我通过设置 Access-Control-Allow-Origin 将特定域添加到我的 express CORS 配置来解决此问题,但现在 API 不会响应来自浏览器的点击。

所以我有点困惑,我希望 API 是开放的,但仍然使用 Stormpath 进行身份验证,但也许这不可能?

【问题讨论】:

标签: angularjs express stormpath


【解决方案1】:

Stormpath AngularJS SDK 有一个示例应用程序,向您展示如何让 CORS 与 AngularJS 和 Express 一起工作。

https://github.com/stormpath/stormpath-sdk-angularjs/tree/master/example/cors-app

您要查找的代码位于server.jsstarting at line 22

var cors = require('cors');
...
/*
  The apiService is your API that you want to protect with
  Stormpath.  We use the CORS module to whitelist the website
  domain, thus allowing it to communicate with the API domain
 */

var apiService = express();

apiService.use(cors({
  origin: websiteDomain,
  credentials: true
}));

apiService.use(stormpath.init(apiService,{ }));

【讨论】:

  • 谢谢,这太完美了!
猜你喜欢
  • 2014-12-12
  • 2017-01-10
  • 2013-08-19
  • 1970-01-01
  • 2014-07-08
  • 2018-10-09
相关资源
最近更新 更多