我正在尝试...@gmail.com
通过 Graph API (C#)将带有电子邮件的用户添加到我的 B2C 目录。我得到这个作为回应:
userPrincipalName 属性的域部分无效。您必须在您的组织中使用经过验证的域名之一。
该系统需要允许任何电子邮件域的用户登录。用户需要登录网站,不能访问 Azure 门户。
有没有办法在不手动添加每个域的情况下完成此操作?
通过Graph API添加用户的代码:
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
var authProvider = new ClientCredentialProvider(confidentialClientApplication);
var graphClient = new GraphServiceClient(authProvider);
var user = new User
{
AccountEnabled = true,
DisplayName = emailAddress,
MailNickname = emailAddress.Split('@').FirstOrDefault(),
UserPrincipalName = emailAddress,
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = tempPassword
}
};
Run Code Online (Sandbox Code Playgroud)