Microsoft.Common.ServicePrincipalSelector UI 元素

一个可让用户选择现有服务主体或注册新应用程序的控件。 选择“新建”时,需执行注册新应用程序的步骤。 选择现有应用程序时,此控件将提供一个文本框,用于输入密码或证书指纹。

UI 示例

可以使用默认应用程序、可以新建应用程序,还可以使用现有应用程序。

使用默认应用程序或新建应用程序

默认视图由 defaultValue 属性中的值确定,“服务主体类型”设置为“新建”。 如果 principalId 属性包含有效的全局唯一标识符 (GUID),则此控件会搜索应用程序的 objectId。 如果用户没有从控件中进行选择,则会应用默认值。

若要注册新的应用程序,请选择“更改选择”,此时会显示“注册应用程序”对话框。 输入名称支持的帐户类型,然后选择“注册”按钮。

Screenshot of Microsoft.Common.ServicePrincipalSelector initial view with default application or create new option.

注册新应用程序后,请使用“身份验证类型”输入密码或证书指纹。

Screenshot of Microsoft.Common.ServicePrincipalSelector authentication options after registering a new application.

使用现有应用程序

若要使用现有应用程序,请选择“选择现有”,然后选择“进行选择”。 使用“选择应用程序”对话框搜索应用程序的名称。 从结果中选择应用程序,然后选择“选择”按钮。 选择应用程序后,控件会显示“身份验证类型”,此时可以输入密码或证书指纹。

Screenshot of Microsoft.Common.ServicePrincipalSelector with select existing application option and authentication type displayed.

架构

{
  "name": "ServicePrincipal",
  "type": "Microsoft.Common.ServicePrincipalSelector",
  "label": {
    "password": "Password",
    "certificateThumbprint": "Certificate thumbprint",
    "authenticationType": "Authentication Type",
    "sectionHeader": "Service Principal"
  },
  "toolTip": {
    "password": "Password",
    "certificateThumbprint": "Certificate thumbprint",
    "authenticationType": "Authentication Type"
  },
  "defaultValue": {
    "principalId": "<default guid>",
    "name": "(New) default App Id"
  },
  "constraints": {
    "required": true,
    "regex": "^[a-zA-Z0-9]{8,}$",
    "validationMessage": "Password must be at least 8 characters long, contain only numbers and letters"
  },
  "options": {
    "hideCertificate": false
  },
  "visible": true
}

备注

  • 必需的属性如下所示:

    • name
    • type
    • label
    • defaultValue:指定默认的 principalIdname
  • 可选属性如下所示:

    • toolTip:将工具提示 infoBalloon 附加到每个标签。
    • visible:隐藏或显示控件。
    • options:指定是否应使证书指纹选项可用。
    • constraints:用于密码验证的正则表达式约束。

示例

下面是 Microsoft.Common.ServicePrincipalSelector 控件的一个示例。 defaultValue 属性将 principalId 设置为 <default guid>(默认应用程序标识符 GUID 的占位符)。

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [],
    "steps": [
      {
        "name": "SPNcontrol",
        "label": "SPNcontrol",
        "elements": [
          {
            "name": "ServicePrincipal",
            "type": "Microsoft.Common.ServicePrincipalSelector",
            "label": {
              "password": "Password",
              "certificateThumbprint": "Certificate thumbprint",
              "authenticationType": "Authentication Type",
              "sectionHeader": "Service Principal"
            },
            "toolTip": {
              "password": "Password",
              "certificateThumbprint": "Certificate thumbprint",
              "authenticationType": "Authentication Type"
            },
            "defaultValue": {
              "principalId": "<default guid>",
              "name": "(New) default App Id"
            },
            "constraints": {
              "required": true,
              "regex": "^[a-zA-Z0-9]{8,}$",
              "validationMessage": "Password must be at least 8 characters long, contain only numbers and letters"
            },
            "options": {
              "hideCertificate": false
            },
            "visible": true
          }
        ]
      }
    ],
    "outputs": {
      "appId": "[steps('SPNcontrol').ServicePrincipal.appId]",
      "objectId": "[steps('SPNcontrol').ServicePrincipal.objectId]",
      "password": "[steps('SPNcontrol').ServicePrincipal.password]",
      "certificateThumbprint": "[steps('SPNcontrol').ServicePrincipal.certificateThumbprint]",
      "newOrExisting": "[steps('SPNcontrol').ServicePrincipal.newOrExisting]",
      "authenticationType": "[steps('SPNcontrol').ServicePrincipal.authenticationType]"
    }
  }
}

示例输出

appId 是所选的或所创建的应用程序注册的 ID。 objectId 是为所选应用程序注册配置的服务主体的 objectId 数组。

未从控件中进行选择时,newOrExisting 属性值为“new”:

{
  "appId": {
    "value": "<default guid>"
  },
  "objectId": {
    "value": ["<default guid>"]
  },
  "password": {
    "value": "<password>"
  },
  "certificateThumbprint": {
    "value": ""
  },
  "newOrExisting": {
    "value": "new"
  },
  "authenticationType": {
    "value": "password"
  }
}

从控件中选择了“新建”或现有应用程序时,newOrExisting 属性值为“existing”:

{
  "appId": {
    "value": "<guid>"
  },
  "objectId": {
    "value": ["<guid>"]
  },
  "password": {
    "value": "<password>"
  },
  "certificateThumbprint": {
    "value": ""
  },
  "newOrExisting": {
    "value": "existing"
  },
  "authenticationType": {
    "value": "password"
  }
}

后续步骤