正在从Java中活动的Azure B2C删除用户[graphClient.USERS(用户id).buildRequest().delete()]

正在从Java中活动的Azure B2C删除用户[graphClient.USERS(用户id).buildRequest().delete()],java,azure,active-directory,azure-active-directory,azure-ad-b2c,Java,Azure,Active Directory,Azure Active Directory,Azure Ad B2c,我正在尝试将用户迁移到Azure B2C Active Directory 早些时候,我从JSON文件中读取并创建“用户”,但是如果JSON中的任何“用户”已经出现在Azure B2C广告中,我会得到一个异常 SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: Request_BadRequest Error message: Another object with the s

我正在尝试将用户迁移到Azure B2C Active Directory

早些时候,我从JSON文件中读取并创建“用户”,但是如果JSON中的任何“用户”已经出现在Azure B2C广告中,我会得到一个异常

SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: Request_BadRequest
Error message: Another object with the same value for property userPrincipalName already exists.
Error message: Resource 'shumi' does not exist or one of its queried reference-property objects are not present.
我用一个简单的try/catch处理所有这些“用户”,跳过它们并将它们移动到JSON中的下一个用户

现在我需要删除流程中的现有用户(一旦我得到上述异常,我将删除该用户)

我试过这个

private void deleteExistingUser(String issuerAssignedId, IGraphServiceClient graphClient) {
    graphClient.users(issuerAssignedId).buildRequest().delete();
    LOG.info("User deleted.");
}
但当上面的代码被点击时,我得到下面的异常

SEVERE: Throwable detail: com.microsoft.graph.http.GraphServiceException: Error code: Request_BadRequest
Error message: Another object with the same value for property userPrincipalName already exists.
Error message: Resource 'shumi' does not exist or one of its queried reference-property objects are not present.
你能告诉我如何进入这里graphClient.users(什么值将进入这里)。buildRequest().delete()

我相信这是因为我正在使用userPrincipalName(issuerasignedid)删除用户,而我应该使用“azure retured user id”(我认为它被称为对象id或用户id)删除用户


是否有一种方法可以获取azure返回的用户id或其他方法来删除该用户?

您应该在此处输入用户对象id或userPrincipalName

您在这里使用“shumi”,因为它的符号是userName

由于您收到错误消息:另一个与属性userPrincipalName具有相同值的对象已经存在。,我认为您已经拥有userPrincipalName

您不需要获取用户id。只需按如下方式删除用户:

await graphClient.Users["{userPrincipalName}"]
    .Request()
    .DeleteAsync();

使用IUserCollectionPage
和查询选项获取列表

        LinkedList<QueryOption> requestOptions = new LinkedList<>();
        
        String query = "identities/any(c:c/issuerAssignedId eq ' issuerAssignedId ' 
        and c/issuer eq ' b2cTenant ')";
        
        requestOptions.add(new QueryOption("$filter", query));
        
        IUserCollectionPage userColl = graphClient.users()
                .buildRequest(requestOptions)
                .get();
        
        List<User> userInfo = userColl.getCurrentPage();
        
        String uId = null;
        
        for (User user : userInfo) {
            userId = user.id;
        }
        
        graphClient.users(uId).buildRequest().delete();
LinkedList requestOptions=新建LinkedList();
String query=“identifications/any(c:c/issuerasignedid eq'issuerasignedid'
和c/发行人eq‘B2C承租人’”;
add(新查询选项(“$filter”,query));
IUserCollectionPage userColl=graphClient.users()
.buildRequest(请求选项)
.get();
List userInfo=userColl.getCurrentPage();
字符串uId=null;
for(用户:userInfo){
userId=user.id;
}
graphClient.users(uId.buildRequest().delete();
这就是如何从Azure b2c广告中删除用户


注意:b2Tenant是“demo.micorsoft.com”(使用您的)

已经修复了它,为它创建了一个用户内容页,并取出一个列表并通过User=User进行迭代。id@sh4r4d好主意!如果我的回答也有帮助,你可以将其标记为已接受。谢谢:)使用查询选项