【问题标题】:How to get an access token using Azure AD b2c via C# code?如何通过 C# 代码使用 Azure AD b2c 获取访问令牌?
【发布时间】:2021-08-31 09:22:06
【问题描述】:

Azure Active Directory B2C 用户密码验证 获取Azure AD b2c auth token 的方法是什么? 尝试使用 Microsoft.Identity.Client 获取访问令牌。 代码:

var appId = "<applicationId/ClientId>";
var b2cAuthority = "https://<applicationUrl>/tfp/<applicationUrl>/<userFlow>";
var b2cScopes = new[] { "<readScope>" };
var tenantId = "<tenantId>";
var userLogin = "<login>";
var userPassword = "<password>";
SecureString securePassword = new NetworkCredential("", userPassword).SecurePassword;
var msalPublicClient = PublicClientApplicationBuilder
   .Create(appId)
   .WithB2CAuthority(b2cAuthority)
   .WithTenantId(tenantId)               
   .Build();
AuthenticationResult authResult = await msalPublicClient
    .AcquireTokenByUsernamePassword(b2cScopes, userLogin, securePassword)
    .WithClaims("emails")  
    .ExecuteAsync(CancellationToken.None)
    .ConfigureAwait(false);

在 .ExecuteAsync() 上抛出异常:AADB2C90108: The orchestration step '1' does not specify a CpimIssuerTechnicalProfileReferenceId when one was expected 有没有什么办法解决这一问题? 我们不想更改任何默认策略来修复它。

【问题讨论】:

  • 您是否使用自定义策略? ROPC 流程?
  • @rbrayb 没有自定义政策
  • @VladyslavFurdak,你设法让它工作了吗?我有完全相同的问题...

标签: azure azure-active-directory azure-ad-b2c


【解决方案1】:

您的用户流程或政策有问题。你将不得不解决这个问题。你的代码很好。

【讨论】:

  • 我有同样的代码和同样的问题。只有用户流,没有自定义策略。类似的登录也适用于 Swagger/SPA 应用程序。
猜你喜欢
  • 1970-01-01
  • 2019-11-21
  • 2017-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-15
  • 1970-01-01
相关资源
最近更新 更多