gpt4 book ai didi

java - 在 Java 中从 Azure B2C Active 中删除用户 [graphClient.users(user-id).buildRequest().delete()]

转载 作者:行者123 更新时间:2023-12-02 23:24:25 24 4
gpt4 key购买 nike

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

之前,我正在创建“用户”,我从 JSON 文件中读取并创建它们,但是如果 JSON 中的任何“用户”已存在于 Azure B2C AD 中,我会遇到异常...

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.

我通过一个简单的 try/catch 来处理所有这些“用户”,然后跳过它们并将它们移动到 JSON 中的下一个用户。

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

我试过这个...

private void deleteExistingUser(String issuerAssignedId, IGraphServiceClient graphClient) {
graphClient.users(issuerAssignedId).buildRequest().delete();
LOG.info("User deleted.");
}

但是当上面的代码被执行时,我遇到了异常......

Error message: Resource 'shumi' does not exist or one of its queried reference-property objects are not present.

你能告诉我如何进入这里graphClient.users(what_value_will_go_here).buildRequest().delete();

我相信发生这种情况是因为我使用userPrincipalName (issuerAssignedId)来删除用户,相反我应该使用“azure retured user id”(它称为Object-id OR user-id 我认为) 删除用户。

有什么方法可以获取 azure 返回的用户 ID 或其他删除用户的方法吗?

最佳答案

使用IUserCollectionPage和QueryOption来获取列表。

        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();

这是从 Azure b2c AD 删除用户的方法

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

关于java - 在 Java 中从 Azure B2C Active 中删除用户 [graphClient.users(user-id).buildRequest().delete()],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67005848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com