2016-11-27 48 views
0

我正在使用Stormpath,並且想要將我的API與客戶端代碼分開(Angular ,使用Stormpath的angular-sdk)。這意味着API將位於與客戶端不同的子域中。一旦我做到了這一點,我就犯了錯誤;Stormpath憑證標誌爲tru時,不能在「Access-Control-Allow-Origin」標頭中使用通配符'*'

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

我解決了這個問題通過添加特定域到我的快遞CORS配置設置Access-Control-Allow-Origin,但現在的API是不會從瀏覽器命中作出迴應。

所以我有點困惑,我更喜歡API被打開,但仍然使用Stormpath進行身份驗證,但也許這不可能?

+0

看看這個教程:https://stormpath.com/blog/angularjs-spring-boot-tutorial 它使用了Spring所以因人而異,但仍然是有幫助的。 –

回答

0

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,{ })); 
+0

謝謝,這是完美的! –

相關問題