如何获得Angular应用程序的授权令牌?
- 前端:角
- 后端:.NET核心API
- 环境:MS Azure;
要求:我们希望.NET Core API接受具有访问令牌的授权UI应用程序的请求。我们目前正在尝试获取访问令牌,以便我们可以在标题中包括并发送到.NET Core API,但是我们面临的问题是,在本地运行Angular应用程序时,我们无法从Online.microsoftonline.com获得访问令牌。而是臭名昭著的CORS错误。
我们可能会怎么做?
- Frontend: Angular
- Backend: .NET core API
- Environment: MS Azure;
Requirement: We want .NET core API to accept requests from authorized UI application who are having access token. We are current trying to get the access token so that we can include in header and send to .NET core API, but we are facing an issue that while running the angular application locally we are unable to get access token from online.Microsoftonline.com instead the infamous CORS error.
What is wrong we may be doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很少有解决方法,
请确保您的API与另一个域没有连接,这可能是无法从CORS策略访问的原因,因此可能是由于这个原因,您将无法调用API 。
例如启用cors属性;
有关更多信息,请参阅此
ms q& a
@deepdave-mt提出的讨论在评论中提出。而且,此博客 | ASP.NET Core API使用Azure AD Auth和用户访问令牌。
There are few of the workarounds,
Make sure that your API is not connected with another domain which can be reason for not able to get access from CORs policy ,so may be for that reason you will not be able to call the API.
For example to enable CORs attribite ;
For more information please refer this
MS Q&A
discussion which is suggested by @DeepDave-MT in comment.And, this Blog|ANGULAR SPA WITH AN ASP.NET CORE API USING AZURE AD AUTH AND USER ACCESS TOKENS.