使用Passport Azure AD时会出现CORS错误
我拥有我的Express API服务器以及Heroku上的水疗中心。该水疗中心使用MSAL使用Azure AD身份验证。使用Passport-azure-AD确保API。一切都在我的本地主机上运作良好,并在获得成功响应的地方提出了要求。但是,在将更改上传到Heroku时,我现在会遇到CORS错误。我已经在Azure AD上注册了API,并将API暴露于我的水疗中心。我仍然会遇到错误的原因吗?
Access to fetch at 'https://myTestApp-server.herokuapp.com/getUsers' from origin 'https://myTestApp.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I have my Express API server as well as the SPA hosted on Heroku. The SPA uses Azure ad authentication using MSAL. The APIs are secured using Passport-azure-ad. Everything was working well in my localhost and the requests made where getting a success response. However on uploading the changes to Heroku I am now getting the CORS error. I have registered the API on Azure AD and exposed the API to my SPA. Any reason why I am still getting the error?
Access to fetch at 'https://myTestApp-server.herokuapp.com/getUsers' from origin 'https://myTestApp.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要避免CORS错误,请确保添加标题如下:
*
以允许所有类似下面的内容:< a href =“ https://i.sstatic.net/hv95f.png” rel =“ nofollow noreferrer”>
.setisoriginallowed(((host)=&gt; true)来修改 cors 策略
或
有关更多详细信息,请请参阅下面的链接:
azure app服务no access-control-allow-allow-origin'标头
no'访问访问权限控制 - 供电-Allow-Origin'标头是在Angular App中的请求资源上存在
3种固定CORS错误的方法以及访问control-allow-allow-allow-hower header如何工作
To avoid the CORS error, make sure to add the header like below:
*
to allow all like below:.SetIsOriginAllowed((host)=> true)"
Or
For more in detail, please refer below link:
Azure App Service No ‘Access-Control-Allow-Origin’ header is present
No 'Access-Control-Allow-Origin' header is present on the requested resource in angular app
3 Ways to Fix the CORS Error and How the Access-Control-Allow-Origin Header Works