简体   繁体   English

Azure AD B2C 声明能否用于 .NET Core Web 应用程序中的授权目的?

[英]Can Azure AD B2C Claims be used for authorization purposes in a .NET Core Web App?

When setting up Azure AD B2C authentication using the Microsoft Identity Platform there is an option to store and return custom claims for a user.使用 Microsoft 身份平台设置 Azure AD B2C 身份验证时,可以选择为用户存储和返回自定义声明。 The question is specifically about when developing a .NET Core Web Application that uses an App Registration to log users in.该问题专门针对开发使用应用注册来登录用户的 .NET Core Web 应用程序。

EDIT: In this scenario, the web app does not call a downstream API - There is a single web app (MVC), the user authenticates against AAD B2C, they use the web app and the controllers on the back-end use an Authorize attribute编辑:在这种情况下,Web 应用程序不调用下游 API - 有一个 Web 应用程序 (MVC),用户针对 AAD B2C 进行身份验证,他们使用 Web 应用程序,后端的控制器使用 Authorize 属性

You can define a custom attribute "TeamId" and return that as a claim to the application that a user logs into - It will be in a claim called "extension_TeamId" in this case and available on the ClaimsPrincipal.您可以定义自定义属性“TeamId”并将其作为声明返回给用户登录的应用程序 - 在这种情况下,它将位于名为“extension_TeamId”的声明中,并且在 ClaimsPrincipal 上可用。

Is it safe to use the value in that claim to determine which tenant a user belongs to, or is it possible for that value to be spoofed by the user, making them appear to be within another tenant - I would class this as authorization information which Microsoft states you should never retrieve from an ID token, only an Access Token:使用该声明中的值来确定用户属于哪个租户是否安全,或者该值是否可能被用户欺骗,使他们看起来在另一个租户中 - 我会将其归类为授权信息Microsoft 声明您永远不应该从 ID 令牌中检索,而只能从访问令牌中检索:

ID tokens are issued by the authorization server and contain claims that carry information about the user. ID 令牌由授权服务器发布,并包含携带有关用户信息的声明。 They can be sent alongside or instead of an access token.它们可以与访问令牌一起发送或代替访问令牌发送。 Information in ID Tokens allows the client to verify that a user is who they claim to be. ID 令牌中的信息允许客户端验证用户是否是他们声称的身份。 ID tokens are intended to be understood by third-party applications. ID 令牌旨在被第三方应用程序理解。 ID tokens should not be used for authorization purposes. ID 令牌不应用于授权目的。 Access tokens are used for authorization.访问令牌用于授权。 The claims provided by ID tokens can be used for UX inside your application, as keys in a database, and providing access to the client application. ID 令牌提供的声明可用于应用程序内部的 UX,作为数据库中的键,并提供对客户端应用程序的访问。

https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens https://docs.microsoft.com/en-us/azure/active-directory/develop/id-tokens

The alternative is to store the data in a table that links a user to a team, where the users B2C ID (Guid) is used to lookup their assigned team from the DB first, rather than taking it straight from their claims and looking up info about that team.另一种方法是将数据存储在将用户链接到团队的表中,其中用户 B2C ID (Guid) 用于首先从数据库中查找其分配的团队,而不是直接从他们的声明中获取并查找信息关于那支球队。

I may be getting confused between ID Tokens and Access Tokens and want to understand what the Microsoft Identity platform is returning in this case.我可能对 ID 令牌和访问令牌感到困惑,并想了解 Microsoft 身份平台在这种情况下返回的内容。 Is the token sent from the .NET Core Web Applications front-end to the backend an ID Token or Access Token?从 .NET Core Web 应用程序前端发送到后端的令牌是 ID 令牌还是访问令牌?

The ID Token returned informs the receiving client application details about how the user authenticated and who he is.返回的 ID 令牌通知接收客户端应用程序有关用户如何进行身份验证以及他是谁的详细信息。 From the ID-token, the local "session/identity" is then created.然后根据 ID 令牌创建本地“会话/身份”。 The ID token is not meant to be passed around to other services and typically it has a very short lifetime. ID 令牌不打算传递给其他服务,通常它的生命周期很短。

The received access token is used by the receiving client to get access to APIs and resources.接收客户端使用接收到的访问令牌来访问 API 和资源。 The client application should not need to look inside the access token.客户端应用程序不需要查看访问令牌内部。

The claims in the ID-token (optionally with the claims from the UserInfo endpoint) ends up in the local user session and can be used to authorize various features in the client application. ID-token 中的声明(可选地与来自 UserInfo 端点的声明)在本地用户会话中结束,并可用于授权客户端应用程序中的各种功能。

So, yes claims from the provider can be used to authorize the users, but you need to understand the different use cases for the ID and access token.因此,是的,来自提供者的声明可用于授权用户,但您需要了解 ID 和访问令牌的不同用例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一个使用 Azure AD B2C 的多个客户端 ID(应用程序 ID)的 ASP.NET Core 2.2 Web API 应用程序 - One ASP.NET Core 2.2 Web API app Using Multiple Client IDs (Application IDs) of Azure AD B2C 无法使用来自我的 asp.net 核心 web 应用程序的 AAD B2C 中的自定义策略登录多租户 Azure AD - unable to sign In for MultiTenant Azure AD using Custom policies in AAD B2C from my asp.net core web app 跨 ASP.Net Core Web 应用程序使用 Azure AD B2C Cookie - Use Azure AD B2C Cookie across ASP.Net Core Web Apps 无法使用 asp.net 核心图 API 在 Azure AD B2C 中创建自定义属性 - Can't create custom attributes in Azure AD B2C with asp.net core Graph API 如何使用 api 连接器和 asp net core web api 通过自定义声明丰富 azure b2c 令牌 - How to enrich azure b2c token with custom claims using api connectors and asp net core web api 使用 Azure AD B2C 使用个人用户帐户登录 ASP.Net Core Web 应用程序 -> API - Sign in to ASP.Net Core Web Application -> API with Individual User Accounts using Azure AD B2C 如何使用 MSAL C#、.net 核心在 Azure AD B2C 用户帐户上重置密码? - How to reset password on Azure AD B2C user account using MSAL C#, .net core? .Net Core 3.1 - 如何为 Azure AD B2C 生成注册链接? - .Net Core 3.1 - how to generate Sign Up link for Azure AD B2C? 使用ASP.NET Core的Azure AD B2C - 无法编辑配置文件 - Azure AD B2C with ASP.NET Core - Unable to go to edit profile ASP.NET 浏览器关闭后核心身份验证未保持登录状态(Azure AD B2C) - ASP.NET Core Auth not staying signed in after browser closes (Azure AD B2C)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM