【问题标题】:Azure AD and Core Idenity Roles HybridAzure AD 和核心身份角色混合
【发布时间】:2021-12-11 11:55:39
【问题描述】:

是否可以同时使用 Azure AD 和核心身份角色?基本上,用户将使用 AD 登录应用程序,我已经这样做了。但是当他们使用该应用程序时,他们的角色将基于 AspNetRoles 和 AspNetUsersRoles 表。我在想我必须使用 ClaimsPrincipal 工厂来扩展用户登录时创建的声明对象。

【问题讨论】:

    标签: azure-active-directory asp.net-core-3.1 claims-based-identity


    【解决方案1】:

    通过使用 ASP.NET 身份,您可以在数据库中本地管理用户,并将用户 Azure AD 作为外部身份提供者,使 AAD 帐户能够登录您的应用程序。您可以识别用户并将其链接到本地​​数据库中的用户。然后,您还可以与本地用户和 Azure AD 用户一起管理角色。

    阅读更多here

    • 使用个人用户帐户创建一个新应用程序。

    • 安装这个包:Microsoft.AspNetCore.Authentication.AzureAD.UI

    • services.AddDbContext(options => options.UseSqlServer(

    • Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity() .AddEntityFrameworkStores(); services.AddAuthentication(sharedOptions => }).AddAzureAD(options => Configuration.Bind("AzureAd", options)).AddCookie();

    • 更新 appsettings.json "AzureAd": { "Instance": "https://login.microsoftonline.com/",

    • "Domain": "xxx.onmicrosoft.com", "TenantId": "xxxxxx-xxxxx-4f08-b544-b1eb456f228d",

    • "ClientId": "xxxxx-xxxxx-4717-9821-e4f718fbece4", "CallbackPath": "/signin-oidc",

    • "CookieSchemeName": "Identity.External" },

    这取决于用户选择使用本地身份验证登录还是 Azure AD Authentication.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2021-11-05
      • 2016-12-24
      • 2023-03-11
      相关资源
      最近更新 更多