使用自定义目标属性配置同步

命名空间:microsoft.graph

可以自定义同步架构,以包括目标目录中定义的自定义属性。 本文介绍如何通过添加名为 officeCode的新字段来自定义 Salesforce 订阅。 你设置了从 Microsoft Entra ID 到 Salesforce 的同步,对于每个用户,你将使用 Microsoft Entra ID 字段中的值填充 officeCode Salesforce 中的字段extensionAttribute10

本文假定你已添加一个应用程序,该应用程序支持通过Microsoft Entra 管理中心同步到租户,你知道应用程序显示名称,并且你具有 Microsoft Graph 的授权令牌。 有关如何获取授权令牌的信息,请参阅 获取访问令牌以调用 Microsoft Graph

按显示名称查找服务主体对象

以下示例演示如何查找显示名称为 Salesforce 的服务主体对象。

请求

GET https://graph.microsoft.com/v1.0/servicePrincipals?$select=id,appId,displayName&$filter=startswith(displayName, 'salesforce')
Authorization: Bearer {Token}

响应

HTTP/1.1 200 OK
Content-Type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals(id,appId,displayName)",
    "value": [
    {
        "id": "167e33e9-f80e-490e-b4d8-698d4a80fb3e",
        "appId": "cd3ed3de-93ee-400b-8b19-b61ef44a0f29",
        "displayName": "Salesforce"
    },
    {
        "id": "8cbbb70b-7290-42da-83ee-89fa3517a977",
        "appId": "b0f2e3b1-fe31-4658-b216-44dcaeabb63a",
        "displayName": "salesforce 1"
    },
    {
        "id": "60443998-8cf7-4e61-b05c-a53b658cb5e1",
        "appId": "79079396-c301-405d-900f-e2e0c2439a90",
        "displayName": "Salesforce Sandbox"
    }
    ]
}

{servicePrincipalId}167e33e9-f80e-490e-b4d8-698d4a80fb3e

列出服务主体上下文中的同步作业

以下示例演示如何获取 jobId 需要使用的 。 通常,响应仅返回一个作业。

请求

GET https://graph.microsoft.com/v1.0/servicePrincipals/60443998-8cf7-4e61-b05c-a53b658cb5e1/synchronization/jobs
Authorization: Bearer {Token}

响应

HTTP/1.1 200 OK
Content-Type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('60443998-8cf7-4e61-b05c-a53b658cb5e1')/synchronization/jobs",
    "value": [
        {
            "id": "SfSandboxOutDelta.e4bbf44533ea4eabb17027f3a92e92aa",
            "templateId": "SfSandboxOutDelta",
            "schedule": {},
            "status": {}
    }
    ]
}

{jobId}SfSandboxOutDelta.e4bbf44533ea4eabb17027f3a92e92aa

获取同步架构

以下示例演示如何获取同步架构。

GET https://graph.microsoft.com/v1.0/servicePrincipals/{servicePrincipalId}/synchronization/jobs/{jobId}/schema
Authorization: Bearer {Token}

注意:为了提高可读性,可能缩短了此处显示的响应对象。 将在实际调用中返回所有属性。

HTTP/1.1 200 OK
Content-Type: application/json

{
  "directories": [
    {
      "id": "66e4a8cc-1b7b-435e-95f8-f06cea133828",
      "name": "Azure Active Directory",
      "objects": [
        {
          "attributes": [
            {
              "anchor": true,
              "caseExact": false,
              "defaultValue": null,
              "metadata": [],
              "multivalued": false,
              "mutability": "ReadWrite",
              "name": "objectId",
              "required": false,
              "referencedObjects": [],
              "type": "String"
            },
            {
              "anchor": false,
              "caseExact": false,
              "defaultValue": null,
              "metadata": [],
              "multivalued": false,
              "mutability": "ReadWrite",
              "name": "streetAddress",
              "required": false,
              "referencedObjects": [],
              "type": "String"
            }
          ],
          "name": "User"
        }
      ]
    },
    {
      "id": "8ffa6169-f354-4751-9b77-9c00765be92d",
      "name": "salesforce.com",
      "objects": []
    }
  ],
  "synchronizationRules": [
    {
      "editable": true,
      "id": "4c5ecfa1-a072-4460-b1c3-4adde3479854",
      "name": "USER_OUTBOUND_USER",
      "objectMappings": [
        {
          "attributeMappings": [
            {
              "defaultValue": "True",
              "exportMissingReferences": false,
              "flowBehavior": "FlowWhenChanged",
              "flowType": "Always",
              "matchingPriority": 0,
              "source": {
                "expression": "Not([IsSoftDeleted])",
                "name": "Not",
                "parameters": [
                  {
                    "key": "source",
                    "value": {
                      "expression": "[IsSoftDeleted]",
                      "name": "IsSoftDeleted",
                      "parameters": [],
                      "type": "Attribute"
                    }
                  }
                ],
                "type": "Function"
              },
              "targetAttributeName": "IsActive"
            }
          ],
          "enabled": true,
          "flowTypes": "Add, Update, Delete",
          "name": "Synchronize Azure Active Directory Users to salesforce.com",
          "scope": null,
          "sourceObjectName": "User",
          "targetObjectName": "User"
        }
      ]
    }
  ]
}

添加 officeCode 属性的定义和属性之间的映射

使用所选纯文本编辑器 (例如,记事本++JSON 编辑器 Online) :

  1. officeCode属性添加属性定义

    • 在目录下,找到名称为 salesforce.com 的目录,然后在对象的数组中找到名为 User 的目录
    • 将新属性添加到列表中,并指定名称和类型,如以下示例所示。
  2. 在 和 extensionAttribute10之间officeCode添加属性映射

    • synchronizationRules 下,找到将Microsoft Entra ID指定为源目录的规则,并将 Salesforce.com 指定为目标目录 ("sourceDirectoryName": "Azure Active Directory", "targetDirectoryName": "salesforce.com") 。
    • 在规则的 objectMappings 中,查找用户 ("sourceObjectName": "User", "targetObjectName": "User") 之间的映射。
    • objectMapping 的 attributeMappings 数组中,添加一个新条目,如以下示例所示。
{  
    "directories": [
    {
        "id": "8ffa6169-f354-4751-9b77-9c00765be92d",
            "name": "salesforce.com",
            "objects": [
            {
                "attributes": [
                        {
                            "name": "officeCode",
                            "type": "String"
                        }
                ],
                "name":"User"
            }]
    }
    ],
    "synchronizationRules": [
        {
        "editable": true,
        "id": "4c5ecfa1-a072-4460-b1c3-4adde3479854",
        "name": "USER_OUTBOUND_USER",
        "objectMappings": [
            {
            "attributeMappings": [
                {
                    "source": {
                            "name": "extensionAttribute10",
                            "type": "Attribute"
                        },
                    "targetAttributeName": "officeCode"
                }
            ],
            "name": "Synchronize Azure Active Directory Users to salesforce.com",
            "scope": null,
            "sourceObjectName": "User",
            "targetObjectName": "User"
            }
        ],
    "priority": 1,
        "sourceDirectoryName": "Azure Active Directory",
        "targetDirectoryName": "salesforce.com"
    }
    ]
}

保存修改后的同步架构

保存更新的同步架构时,请确保包括整个架构,包括未修改的部分。 此请求会将现有架构替换为你提供的架构。

PUT https://graph.microsoft.com/v1.0/servicePrincipals/{servicePrincipalId}/synchronization/jobs/{jobId}/schema
Authorization: Bearer {Token}

{
    "directories": [..],
    "synchronizationRules": [..]
}

如果成功保存架构,请求将 204 No Content 返回响应代码。 在同步作业的下一次迭代中,它将开始重新处理Microsoft Entra ID中的所有帐户,并将新映射应用于所有预配的帐户。