Asp.net core 当我使用Microsoft Identity AddSignIn而不是旧的解决方案AddAuthentication CORS时,';行不通

Asp.net core 当我使用Microsoft Identity AddSignIn而不是旧的解决方案AddAuthentication CORS时,';行不通,asp.net-core,azure-authentication,microsoft-identity-platform,Asp.net Core,Azure Authentication,Microsoft Identity Platform,因此,我使用Microsoft.Identity.Web的预览版本进行Azure身份验证,它运行良好。 但我们的前端是React,并在其他地方托管。因此,我们需要为此启用Cors。 但我得到一个Cors错误,如下所示: 在'https://login.microsoftonline.com/....“(已从中重定向”https://localhost:44323/imrprojects/search“)起源”http://localhost:3000'已被CORS策略阻止:对飞行前请求的响应未通

因此,我使用Microsoft.Identity.Web的预览版本进行Azure身份验证,它运行良好。 但我们的前端是React,并在其他地方托管。因此,我们需要为此启用Cors。 但我得到一个Cors错误,如下所示:

在'https://login.microsoftonline.com/....“(已从中重定向”https://localhost:44323/imrprojects/search“)起源”http://localhost:3000'已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在'access control Allow Origin'标头。如果不透明响应满足您的需要,请将请求的模式设置为“no cors”,以获取禁用cors的资源

如果我更改代码并使用旧的soution,它工作得很好! startup.cs中的代码:

 //services.AddAuthentication(sharedOptions =>
            //{
            //    sharedOptions.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
            //})
            //.AddAzureAdBearer(options => Configuration.Bind("AzureAd", options));

            services.AddSignIn(Configuration);
如果我使用services.AddAuthentication,它会工作,但当我使用services.AddSignIn时,它不会工作


顺便说一句,我已经准备好了services.AddCors和app.UseCors。

Thansk juunas!你是对的。我想我必须使用AppProtectedWebAPI

现在我在前端遇到这个错误,但我想我需要在应用程序注册中添加作用域或角色


在承载令牌中未找到作用域或角色声明

我认为您需要使用AddProtectedWebApi()或类似的方法来添加承载令牌身份验证。您似乎正在添加交互式身份验证。是您使用Azure AD来投影web API吗?就是这样。我添加了一些角色,给自己分配了一个角色,现在一切都正常了。