尝试调用 B2C 登录时 Cors no-access-control-allow-origin [英] Cors no-access-control-allow-origin when trying to call B2C login

查看:10
本文介绍了尝试调用 B2C 登录时 Cors no-access-control-allow-origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解决这个错误,我有一个 .net core web api,里面有一个 react 应用程序(net core react 模板)

我还添加了cors:

 services.AddCors(options =>{options.AddPolicy("AllowMyOrigin",建造者 =>builder.WithOrigins(https://localhost:44300").AllowAnyHeader().AllowAnyMethod().AllowCredentials());});

我尝试了多种方法,但无法克服此错误.

我在网上找到了大量可以尝试的材料,但似乎没有任何效果,我觉得我错过了一些非常明显的东西?

有人能指出我正确的方向吗.

我希望应该有一个允许源头:

我还尝试使用 Mosif 浏览器扩展程序打开 cors,这阻止了 cors 错误的显示,但现在我打开了 404(未找到):

<块引用>

I cannot resolve this error, i have a .net core web api, with a react application inside of it ( net core react template )

I have also added cors:

      services.AddCors(options =>
        {
            options.AddPolicy("AllowMyOrigin",
            builder => builder.WithOrigins("https://localhost:44300")
            .AllowAnyHeader()
            .AllowAnyMethod()
            .AllowCredentials()
            );
        });

I have tried multiple things but i cant get past this error.

I have found loads of material online to try and nothing seems to work i feel like i am missing something really obvious?

Can someone point me in the right direction.

I expect that there should be an allow origin header:

I also tried using the Mosif browser extension to turn cors on, this stoped the cors error from showing but now i have a 404 (notfound ) on:

https://login.microsoftonline.com/tfp/domainname.onmicrosoft.com/b2c_1_sign_up/v2.0/.well-known/openid-configuration

解决方案

You mention that you get an 404 error when opening the openid-configuration url. This means that part of your configuration is incorrect. You must be able to open this url in your browser and get back a JSON document. Copy it to a new tab and tweak it until you get back a result.

Please double check your configured policy and tenant name. The full url usually looks like this:

https://tenantname.b2clogin.com/tenantname.onmicrosoft.com/<policy-name>/v2.0/.well-known/openid-configuration
https://tenantname.b2clogin.com/tenantname.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=<policy-name>
https://login.microsoftonline.com/tfp/tenantname.onmicrosoft.com/<policy-name>/v2.0/.well-known/openid-configuration

All of these are equally valid and can be used depending on your scenario.

The config should then look something like this:

authentication.initialize({
    instance: 'https://tenantname.b2clogin.com/',
    tenant: 'tenantname.onmicrosoft.com',

Another issue might be if your B2C tenant quite new, Microsoft could be blocking support for microsoftonline for your tenant. In this case, try switching to the b2clogin.com domain as your instance.

You can see a possible value for this url when opening the user flow in the Azure Portal.

As a sidenote, I would suggest switching to a different react library. The one you are using is not really being maintained. We are currently using https://github.com/syncweek-react-aad/react-aad

这篇关于尝试调用 B2C 登录时 Cors no-access-control-allow-origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆