通过


创建应用程序

命名空间:microsoft.graph

创建新的 application 对象。 当 @odata.type 属性设置为 #microsoft.graph.agentIdentityBlueprint时,此 API 还可以创建 agentIdentityBlueprint 对象。

重要

不要在 API 文档或代码示例中共享应用程序客户端 ID (appId) 。

此 API 可用于以下国家级云部署

全局服务 美国政府 L4 美国政府 L5 (DOD) 由世纪互联运营的中国

权限

为此 API 选择标记为最低特权的权限。 只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) Application.ReadWrite.All AgentIdentityBlueprint.Create
委派(个人 Microsoft 帐户) Application.ReadWrite.All 不可用。
应用程序 Application.ReadWrite.OwnedBy AgentIdentityBlueprint.Create、Application.ReadWrite.All

重要

对于使用工作或学校帐户的委派访问,必须为管理员分配受支持的Microsoft Entra角色或授予此操作所需权限的自定义角色。 此操作支持以下内置角色,这些角色仅提供所需的最小特权:

  • 非管理员成员或具有默认用户权限的来宾,除非 租户管理员具有受限访问权限
  • 应用程序开发人员 - 即使管理员限制对成员和来宾的访问权限,也可以创建应用;向具有此角色的主体分配了他们创建的应用的所有权
  • 目录编写器 - 更新扩展属性
  • 混合标识管理员 - 仅更新基本属性
  • 安全管理员
  • 云应用程序管理员
  • 应用程序管理员

HTTP 请求

POST /applications

请求标头

名称 说明
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权
Content-Type application/json. 必需。

请求正文

在请求正文中,提供 application 对象的 JSON 表示形式。 请求正文必须包含 displayName,这是必需属性。 若要创建 agentIdentityBlueprint,还要将 @odata.type 属性设置为 #microsoft.graph.agentIdentityBlueprint

创建 agentIdentityBlueprint 时,可以选择设置 managerApplications 属性。 仅代理标识蓝图对象支持此属性。 在非代理蓝图应用程序上设置 managerApplications 将返回错误 400 Bad Request 。 仅Microsoft第一方应用程序 ID 可以添加为管理器;添加第三方应用程序将返回错误 400 Bad Request 。 允许的最大数目为 10 个管理器应用程序;超过此限制将返回错误 400 Bad Request

响应

如果成功,此方法在201 Created响应正文中返回响应代码和 applicationIdentityBlueprint 对象。

示例

示例 1:使用默认设置创建应用程序

请求

以下示例显示了一个请求。

POST https://graph.microsoft.com/v1.0/applications
Content-type: application/json

{
  "displayName": "Display name"
}

响应

以下示例显示了相应的响应。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

HTTP/1.1 201 Created
Content-type: application/json

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity",
    "id": "03ef14b0-ca33-4840-8f4f-d6e91916010e",
    "deletedDateTime": null,
    "isFallbackPublicClient": null,
    "appId": "631a96bc-a705-4eda-9f99-fdaf9f54f6a2",
    "applicationTemplateId": null,
    "identifierUris": [],
    "createdDateTime": "2019-09-17T19:10:35.2742618Z",
    "displayName": "Display name",
    "isDeviceOnlyAuthSupported": null,
    "groupMembershipClaims": null,
    "optionalClaims": null,
    "addIns": [],
    "publisherDomain": "contoso.com",
    "samlMetadataUrl": "https://graph.microsoft.com/2h5hjaj542de/app",
    "signInAudience": "AzureADandPersonalMicrosoftAccount",
    "tags": [],
    "tokenEncryptionKeyId": null,
    "api": {
        "requestedAccessTokenVersion": 2,
        "acceptMappedClaims": null,
        "knownClientApplications": [],
        "oauth2PermissionScopes": [],
        "preAuthorizedApplications": []
    },
    "appRoles": [],
    "publicClient": {
        "redirectUris": []
    },
    "info": {
        "termsOfServiceUrl": null,
        "supportUrl": null,
        "privacyStatementUrl": null,
        "marketingUrl": null,
        "logoUrl": null
    },
    "keyCredentials": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [],
    "requiredResourceAccess": [],
    "web": {
        "redirectUris": [],
        "homePageUrl": null,
        "logoutUrl": null,
        "implicitGrantSettings": {
            "enableIdTokenIssuance": false,
            "enableAccessTokenIssuance": false
        }
    }
}

示例 2:创建新应用程序并添加密码密码

请求

POST https://graph.microsoft.com/v1.0/applications
Content-type: application/json

{
  "displayName": "MyAppName",
  "passwordCredentials": [
    {
      "displayName": "Password name"
    }
  ]
}

响应

以下示例显示了相应的响应。 响应对象中的 secretText 属性包含Microsoft Entra ID生成的强密码或机密,长度为 16-64 个字符。 将来无法检索此密码。

注意:为了提高可读性,可能缩短了此处显示的响应对象。

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

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity",
    "id": "83ab4737-da9d-4084-86f2-f8fbec220647",
    "deletedDateTime": null,
    "appId": "9519e58c-bd06-4120-a7fd-2220d4de8409",
    "applicationTemplateId": null,
    "disabledByMicrosoftStatus": null,
    "createdDateTime": "2024-04-01T19:10:02.6626202Z",
    "displayName": "MyAppName",
    "description": null,
    "keyCredentials": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [
        {
            "customKeyIdentifier": null,
            "displayName": "Password name",
            "endDateTime": "2026-04-01T19:10:02.6576213Z",
            "hint": "puE",
            "keyId": "09a0c91a-1bc3-4eaf-a945-c88c041fad6c",
            "secretText": "1234567890abcdefghijklmnopqrstuvwxyzabcd",
            "startDateTime": "2024-04-01T19:10:02.6576213Z"
        }
    ],
    "publicClient": {
        "redirectUris": []
    }
}