Azure B2C在我的本地机器上工作,但在Azure上不起作用

发布于 2025-02-10 13:53:10 字数 1050 浏览 0 评论 0原文

我创建了一个调用Web API(.NET)并使用Azure AD B2C进行身份验证的大型应用程序。这在我本地的机器上正常工作。我可以通过登录屏幕进行身份验证,并调用相关端点。一旦我将应用程序部署到Azure,我会在浏览器上获得此错误: 信息:microsoft.aspnetcore.authorization.defaultauthorizationservice [2] 授权失败。这些要求没有得到满足: 拒绝义义授权:需要经过身份验证的用户 无法加载资源:服务器以401(未授权)的状态响应

在Glazor(ui)端,我已经设置了此设置:

"AzureAd": {
    "Authority": "https://CarehomeRoomBookingTest.b2clogin.com/CarehomeRoomBookingTest.onmicrosoft.com/B2C_1_SignUpIn",
    "ClientId": "77##############################",
    "ClientSecret": "99#########################",
    "ValidateAuthority": false
  }

在Web API端,我已经设置了此设置:

"AzureAdB2C": {
    "Instance": "https://CarehomeRoomBookingTest.b2clogin.com",
    "ClientId": "16#############################",
    "Domain": "CarehomeRoomBookingTest.onmicrosoft.com",
    "SignedOutCallbackPath": "/signout/B2C_1_susi_reset_v2",
    "SignUpSignInPolicyId": "B2C_1_SignUpIn",
    "TenantId": "38#############################"
  }

为什么会当应用程序在Azure上部署和托管时,这会发生吗?

I have created a Blazor application that calls a Web API(.Net) and uses Azure AD B2C for authentication. This works fine on my local machine. I can authenticate via the login screen and call the relevant endpoint. Once I deploy the application to Azure I get this error on the browser:
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user
Failed to load resource: the server responded with a status of 401 (Unauthorized)

On the Blazor(UI) side I have this set up:

"AzureAd": {
    "Authority": "https://CarehomeRoomBookingTest.b2clogin.com/CarehomeRoomBookingTest.onmicrosoft.com/B2C_1_SignUpIn",
    "ClientId": "77##############################",
    "ClientSecret": "99#########################",
    "ValidateAuthority": false
  }

On the Web API side I have this set up:

"AzureAdB2C": {
    "Instance": "https://CarehomeRoomBookingTest.b2clogin.com",
    "ClientId": "16#############################",
    "Domain": "CarehomeRoomBookingTest.onmicrosoft.com",
    "SignedOutCallbackPath": "/signout/B2C_1_susi_reset_v2",
    "SignUpSignInPolicyId": "B2C_1_SignUpIn",
    "TenantId": "38#############################"
  }

Why would this be happening when the application is deployed and hosted on Azure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2025-02-17 13:53:10

请检查您是否有以下情况:

1。请参阅前端应用需要使用的API范围是否正确。这样,它将获得用于API的访问令牌。注册
通过暴露API的API应用程序注册范围
部分并使用前端应用中的范围。

和授予管理员同意:

”在此处输入图像描述”

您的范围将在这种方式中出现

确保在代码中的Auth中将其后端API暴露的范围包括


  1. 委派权限是问题。请参阅
    get-401-unauthorized-enauthorized-error-eror-stackoverflow

Please check if any of below is your case:

1.See if scope for your API that Your front-end app needs to use is correct. This way it will get an access token which is meant for your API. Register a
scope for your API app registration through the Expose an API
section and use the scope in your front-end app.

enter image description here

and grant admin consent :

enter image description here

Your scopes will be present this way
enter image description here

Please make sure to include the scopes exposed in the portal for your backend api in the auth in your code

  1. Also please check if you have given proper permissons or if use of
    delegated permissions is the issue .See
    getting-401-unauthorized-error-StackOverflow
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文