简体   繁体   English

多租户spa应用程序和授权中的Identityserver和asp.net身份

[英]Identityserver and asp.net identity in multitenant spa application and authorisation

I have a spa application with a .net core 2 api. 我有一个带有.net core 2 api的spa应用程序。 I would like to use identityserver 4 so that in future i can also provide a sso solution and allow access to my other api/applications. 我想使用Identityserver 4,以便将来我也可以提供sso解决方案并允许访问我的其他api /应用程序。 I have a database that contains the all user information (along with tenant information) for all tenants that identityserver4 will connect with. 我有一个数据库,其中包含Identityserver4将与其连接的所有租户的所有用户信息(以及租户信息)。 Each tenant has their own database for the spa application. 每个租户都有自己的spa应用程序数据库。

Should the api access token i get from identityserver contain role information in the claims and if so where are the roles set up(on the same database as the users or in the tenant specific databases? Im not sure on how to then know that those roles are for which api. for example if i request the api1 scope can i get back a list of roles for that user that are just for that scope and if i request api2 scope get back a different list of roles for that user etc. 我从Identityserver获得的api访问令牌是否应在声明中包含角色信息,如果是,则在何处设置角色(在与用户相同的数据库中或在租户特定的数据库中?)我不确定如何知道这些角色是针对哪个api的。例如,如果我请求api1范围,我可以获取该用户的角色列表,而该角色仅用于该范围,如果我请求api2范围,则可以获取该用户的角色列表等。

The documentation on identityserver and the docs on microsoft appear to me to contradict the way to approach this. 在我看来,identityserver上的文档和microsoft上的文档与解决此问题的方法相矛盾。

Generally role based authentication is getting phased out when oidc/oauth2 is in place because of the exact conflict that you are describing. 通常,由于要描述的确切冲突,当oidc / oauth2就绪时,基于角色的身份验证将被淘汰。 Unless all of your web applications/api's will be respecting the central roles that you would define in your asp.net identity - then there is little to no benefit including them in the access token. 除非您所有的Web应用程序/ api都将尊重您在asp.net身份中定义的核心角色-否则将访问令牌包含在它们中几乎没有好处。

If you plan to have central role system that your other applications will respect and base their authorisation on - then I'd recommend setting the asp.net identity with Identity Server 4 in a single database, creating an Identity Resource for "roles" and including the user specific roles as a claim in the token when the "roles" scope is requested by the client. 如果您打算使用其他应用程序将遵循的中央角色系统并以其为基础进行授权,那么我建议您在单个数据库中使用Identity Server 4设置asp.net身份,为“角色”创建一个身份资源,包括当客户端请求“角色”范围时,将用户特定角色作为令牌中的声明。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM