问题描述
我正在尝试执行get()调用以检查b2c目录中的现有用户,因为我正在使用
I am trying to implement get() call for checking the existing users in b2c directory, for that I am using
User user = graphClient.users("422a535b-a60d-4e5f-833e-2789b32ca04f").buildRequest().get();
这将返回用户数据,但是我只能这样做,因为我有在创建用户时发出的user_id.
This is returning the user data, however I am only able to do this because I have user_id which was issued at the time of creation of user.
User buildUserRequest = graphClient.users()
.buildRequest()
.post(createNewUser);
return buildUserRequest.id;
我有一群尝试迁移的JSON格式的用户,迁移工作正常,JSON看起来像这样:
I am having a bunch of users in JSON format that I am trying to migrate, the migration is working fine, JSON looking like this :
{
"users": [
{
"displayName": "Sharad Dutta",
"givenName": "",
"surname": "",
"extension_user_type": "user",
"identities": [
{
"signInType": "emailAddress",
"issuerAssignedId": "00bonded007@gmail.com"
}
],
"extension_timezone": "VET",
"extension_locale": "en-GB",
"extension_tenant": "EG12345"
},
{
"displayName": "Wayne Rooney",
"givenName": "Wayne",
"surname": "Rooney",
"extension_user_type": "user",
"identities": [
{
"signInType": "userName",
"issuerAssignedId": "00bonded007"
}
],
"extension_timezone": "VET",
"extension_locale": "en-GB",
"extension_tenant": "EG12345"
}
]
}
创建用户时,只要在活动目录中不存在issuerAssignedId,它就可以正常工作.我想处理一种使用get()请求检查issuerAssignedid的情况,如果用户存在于目录中,请跳过它,以使代码不会因异常而中断或退出.
When I am creating a user, as long as the issuerAssignedId is not existing in the active directory, it working fine. I want to handle a case where I am checking issuerAssignedid using get() request, if user exist in directory, skip it so that code will not break or will get out due to exception.
我可以使用try/catch来执行此操作,但是可以使用issuerAssignedId代替user_id来检查b2c中是否存在该用户,如果是,则跳过该用户.
I can do this using try/catch but can I use issuerAssignedId in place of user_id to check if user is existing in the b2c, if yes, then skip for that user.
推荐答案
使用此:
LinkedList<QueryOption> requestOptions = new LinkedList<>();
requestOptions.add(new QueryOption("$filter", "identities/any(c:c/issuerAssignedId eq '00bonded007@gmail.com' and c/issuer eq 'contoso.onmicrosoft.com')"));
IUserCollectionPage Users = graphClient.users()
.buildRequest(requestOptions)
.get();
请注意,您应该将contoso.onmicrosoft.com
修改为您的Azure B2C租户.
Please note that you should modify the contoso.onmicrosoft.com
to your Azure B2C tenant.
这篇关于使用"issuerAssignedId";作为对b2c目录的get()调用,以检查用户是否存在. [JAVA]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!