【问题标题】:What is the easiest way to integrate Azure AD B2C with Azure App Service将 Azure AD B2C 与 Azure 应用服务集成的最简单方法是什么
【发布时间】:2019-05-03 17:08:59
【问题描述】:

以前我一直使用MobileServiceClient.LoginAsync(..) 来启动与社交身份提供者的身份验证流程。

最近我设置了 Azure B2C - 我使用 Microsoft.Identity.Client.PublicClientApplication.AcquireTokenAsync(..) 在浏览器中启动身份验证并获取 JSON Web 令牌:

我可以使用来自 B2C 的 JSON Web 令牌向 Azure 应用服务进行身份验证吗?

我可以使用以下方法对 Azure 应用服务进行身份验证吗?

MobileServiceClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, [JWT HERE])

有没有更简单的方法来使用 Azure 应用服务 + Azure B2C 进行身份验证?

谢谢, 汤姆。

【问题讨论】:

  • 有不少examples available,我猜你的场景在那里?
  • 现在有任何进程吗?

标签: azure-web-app-service azure-ad-b2c


【解决方案1】:

您提供的代码是Integrating Azure Active Directory B2C with Azure Mobile Apps

方法CreateOptionsFromPolicy将Policy名称作为输入参数,并返回一个OpenIdConnectAuthenticationOptions类型的对象,该对象负责控制OpenID连接中间件。

TokenValidationParameters 用于存储验证令牌所需的信息,我们只需在此处更改 2 个设置,NameClaimTypeSaveSigninToken

private OpenIdConnectAuthenticationOptions CreateOptionsFromPolicy(string policy)
{
    return new OpenIdConnectAuthenticationOptions
     {
         // For each policy, give OWIN the policy-specific metadata address, and
         // set the authentication type to the id of the policy
         MetadataAddress = String.Format(aadInstance, tenant, policy),
         AuthenticationType = policy,
         // These are standard OpenID Connect parameters, with values pulled from web.config  
         ClientId = clientId,
         RedirectUri = redirectUri,
         PostLogoutRedirectUri = redirectUri,
         Notifications = new OpenIdConnectAuthenticationNotifications
         {
             AuthenticationFailed = AuthenticationFailed
         },
         Scope = "openid",
         ResponseType = "id_token",
         // This piece is optional - it is used for displaying the user's name in the navigation bar.
         TokenValidationParameters = new TokenValidationParameters
         {
            NameClaimType = "name",
            SaveSigninToken = true //important to save the token in boostrapcontext
         }
    };
}

如果您想将 Azure AD B2C 与 Web App 集成,您可以参考此article 和此one

【讨论】:

    猜你喜欢
    • 2018-01-25
    • 2018-01-12
    • 2019-02-11
    • 1970-01-01
    • 2017-01-09
    • 2023-01-23
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    相关资源
    最近更新 更多