我有一个react前端,它位于azure b2c登录的后面,如果用户在我的租户中注册,它允许用户登录。
然后我向我的后台发送访问令牌,我使用";react aad-msal":
signInAuthProvider.getAccessToken({
scopes: ["https://tenantname.onmicrosoft.com/api/scope_name"],
});
当我通过承载身份验证头将这个令牌发送到我的.net内核3.1后端时,我收到一个401。
我正在使用addazureadbearer服务:
services.AddAuthentication(AzureADDefaults.JwtBearerAuthenticationScheme)
.AddAzureADBearer(options => Configuration.Bind("AzureAd", options));
我的配置部分看起来是这样的:
"AzureAd": {
"Instance": "https://login.microsoftonline.com/tenantname",
"TenantId": "tenantid",
"ClientId": "clientid",
"Audience": "https://tenantname.onmicrosoft.com/api/api.access"
}
我相信这是在做某种交叉检查,因为我得到了401——连接azure不是一个错误。
您需要使用b2c进行身份验证,而不是使用AAD
{
"AzureAdB2C": {
"Instance": "https://<your tenant name>.b2clogin.com",
"ClientId": " your client id",
"Domain": "your tenant domain",
"TenantId": "your tenant id",
"SignUpSignInPolicyId": "your policy name"
}
请参阅本github上的b2c 核心网API