首页 > 解决方案 > AADSTS50020 来自身份提供商“live.com”的用户帐户“xxx@zbc.com”在租户“xx-xx-xx-xx”中不存在 C# Winforms 中的错误

问题描述

我需要AAD B2C AuthenticationC# Winforms应用程序中实现。

我已经在portal.azure.com注册了我的应用程序,还添加了用户,并在应用程序身份验证中添加了“移动和桌面应用程序”Azure AD B2CUser Flows(Sign up and sign in, Password Reset, Profile Editing)xxx@zbc.comPlatform

我在我的Login屏幕中使用以下代码。

string ClientId = "9xXxXxXx-7XxX-4XxX-9XxX-aXxXxXxXxXxX";
string Tenant = "exXxXxXx-9XxX-4XxX-XxX-8XxXxXxXxXxX";
IPublicClientApplication PublicClientApp;

PublicClientApp = PublicClientApplicationBuilder.Create(ClientId)
                            .WithRedirectUri("https://aaa.xxx.com/oauth2/nativeclient")
                            .WithDefaultRedirectUri()
                            .WithAuthority(AzureCloudInstance.AzurePublic, Tenant)
                            .Build();
string token = PublicClientApp.UserTokenCache;

private async void button1_Click(object sender, EventArgs e)
{
      var _scopes = new string[] { "user.read" }.AsEnumerable();
      var authResult = await PublicClientApp.AcquireTokenInteractive(_scopes)
                                    .WithUseEmbeddedWebView(true)
                                    .ExecuteAsync();
}

当我运行代码时,我得到了用于登录的弹出窗口,在 此处输入图像描述

我已经输入了电子邮件,然后在单击登录时输入了密码Wrong Password。然后我从同一页面重置密码并Sign In再次尝试。现在新的错误消息像......

AADSTS50020: User account 'xxx@zbc.com' from identity provider 'live.com' does not exist in 
tenant 'XXX' and cannot access the application '9xXxXxXx-7XxX-4XxX-9XxX-aXxXxXxXxXxX'(XXX) 
in that tenant. The account needs to be added as an external user in the tenant first. 
Sign out and sign in again with a different Azure Active Directory user account. c# winforms

请给我一个解决这个问题的方法......在此先感谢......

标签: c#azurewinforms

解决方案


错误指出帐户“xxx@zbc.com”不是注册应用程序的 AAD 租户 (XXX) 的一部分。

xxx@zbc.com - 同样来自错误 - 用户似乎是真实帐户(@outlook.com、@hotmail.com 等)

所以要解决这个问题 -

登录到您已在其中注册应用程序的租户 (XXX)。

将您的真实帐户 (xxx@zbc.com) 作为外部用户添加到租户。

有关添加外部帐户的详细步骤,您可以参考以下文章

https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/add-external-user?view=azure-devops

或者,您可以更改应用程序以支持租户以外的帐户 (XXX)

在此处输入图像描述

目前,从错误中 - 我假设您的配置设置为仅在此组织目录中的帐户

您必须将其更改为第三个选项: 任何组织目录中的帐户

这可以更改 Azure -> Azure Active Directory -> 管理 -> 应用注册 -> 应用名称 -> 支持的帐户类型

在此处输入图像描述

您可以参考以下链接了解详细步骤:

https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-modify-supported-accounts


推荐阅读