“No 'Access-Control-Allow-Origin' header is present” for redirected request to https://login.microsoftonline.com/

我是研究僧i 提交于 2019-11-29 17:01:37

The issue is because you're trying to call the /api/auth/aad OAuth route via Ajax instead of linking to it directly in your page.

You can't call the AAD OAuth route via Ajax since the url it redirects to that's used to capture the clients authorization (https://login.microsoftonline.com/..) doesn't allow CORS as indicated in the error that you're seeing.

This isn't a ServiceStack CORS issue which you don't need in order to talk to your local API's (i.e. http://localhost:23589) since its hosted in the same domain as the HTML page. CORS (Cross-origin resource sharing) is needed when using Ajax to access a resource outside of the domain (i.e. https://login.microsoftonline.com/..) which since it doesn't allow CORS will not let you access that url via Ajax.

Remove the last slash in your url "http://localhost"

As mythz explained in his answer, CORS is not allowed from your originating domain. You are, however, allowed to register your application with Microsoft Azure(?) Active Directory so that it can display a separate login dialog that will return a callback to your application as soon as authentication succeeds.

For more information about the AAD login flow (mind you, this is a NodeJS example, not bare javascript, but the same logic applies) check out Getting started with Azure AD.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!