获取 resourcePolicyDefinition

命名空间:microsoft.graph

重要

Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。

读取 resourcePolicyDefinition 对象的属性。

客户创作的定义响应包括 JSON @odata.etag 批注中的当前 ETag 或 ETag 纯文本响应的标头。 在更新请求的标头中If-Match使用此值。

设置为 Accept: text/plain 检索单个客户创作、内置或已删除定义的未转义 Rego 策略。

API 可用性

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

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

权限

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

权限类型 最低特权权限 更高特权权限
委派(工作或学校帐户) ResourcePolicyDefinition.Read.All ResourcePolicyDefinition.ReadWrite.All
委派(个人 Microsoft 帐户) 不支持。 不支持。
应用程序 ResourcePolicyDefinition.Read.All ResourcePolicyDefinition.ReadWrite.All

重要

对于使用工作或学校帐户的委派访问权限,必须为登录用户分配受支持的 Microsoft Entra 角色 或授予此操作所需权限的自定义角色。 资源策略读取者 是此操作支持的最小特权角色。

HTTP 请求

GET /admin/resourcePolicy/definitions/{resourcePolicyDefinition-uniqueName}
GET /admin/resourcePolicy/builtInDefinitions/{resourcePolicyDefinition-uniqueName}
GET /admin/resourcePolicy/deletedItems/definitions/{resourcePolicyDefinition-uniqueName}

可选的查询参数

对于活动定义的 JSON 表示形式,用于 $expand 包含 分配 或 previousVersions。 若要了解一般信息,请参阅 OData 查询参数。

请求标头

名称 说明
接受 application/json (默认) 或 text/plain. 可选。 用于 text/plain 仅检索 Rego 策略。
Authorization 持有者 {token}。 必填。 详细了解 身份验证和授权。

请求正文

不要提供请求正文。

响应

如果成功,此方法将返回 200 OK。 使用 Accept: application/json或省略 Accept 时,响应正文是 resourcePolicyDefinition 对象。 使用 , Accept: text/plain响应仅具有 Content-Type: text/plain 且包含未转义的 Rego 策略,而不是 JSON 定义对象。

示例

示例 1:获取 JSON 定义

请求

GET https://graph.microsoft.com/beta/admin/resourcePolicy/definitions/require_application_name
Accept: application/json

响应

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

{
  "@odata.type": "#microsoft.graph.resourcePolicyDefinition",
  "@odata.etag": "\"972dd856-91ff-4539-be09-50ea8235b76c\"",
  "uniqueName": "require_application_name",
  "createdDateTime": "2026-10-22T12:00:00Z",
  "lastModifiedDateTime": "2026-10-22T12:00:00Z",
  "displayName": "Require an application name",
  "description": "Require applications to have a display name",
  "category": "identityAndTenant",
  "version": "1.0.0",
  "deletedDateTime": null,
  "rule": {
    "appliesTo": {
      "operations": "create,updateOrUpsert",
      "resourceName": "microsoft.graph.application",
      "includeDerivedTypes": true
    },
    "policy": "package graph.require_application_name[\"1.0.0\"]\n\n__metadata__ := {\n  \"title\": \"Require an application name\",\n  \"description\": \"Require applications to have a display name\",\n  \"category\": \"identityAndTenant\",\n  \"selector\": {\n    \"resourceName\": \"microsoft.graph.application\",\n    \"operations\": [\n      \"create\",\n      \"updateOrUpsert\"\n    ]\n  }\n}\n\ndefault deny := {\"result\": false, \"reasons\": []}\n\ndeny := {\"result\": true, \"reasons\": [\"A display name is required.\"]} if {\n  object.get(input.resource, \"displayName\", \"\") == \"\"\n}\n"
  },
  "paramsSchema": null
}

示例 2:获取定义作为纯文本策略

请求

GET https://graph.microsoft.com/beta/admin/resourcePolicy/definitions/require_application_name
Accept: text/plain

响应

HTTP/1.1 200 OK
Content-Type: text/plain
ETag: "972dd856-91ff-4539-be09-50ea8235b76c"

package graph.require_application_name["1.0.0"]

__metadata__ := {
  "title": "Require an application name",
  "description": "Require applications to have a display name",
  "category": "identityAndTenant",
  "selector": {
    "resourceName": "microsoft.graph.application",
    "operations": ["create", "updateOrUpsert"]
  }
}

default deny := {"result": false, "reasons": []}

deny := {"result": true, "reasons": ["A display name is required."]} if {
  object.get(input.resource, "displayName", "") == ""
}

示例 3:获取内置定义作为纯文本策略

请求

GET https://graph.microsoft.com/beta/admin/resourcePolicy/builtInDefinitions/microsoft_block_implicit_grant_flow_enablement
Accept: text/plain

响应

响应将缩短为仅显示包声明。 完整响应包含内置策略的 Rego 文本。

HTTP/1.1 200 OK
Content-Type: text/plain

package graph.microsoft_block_implicit_grant_flow_enablement["1.0.0"]

示例 4:以纯文本策略的形式获取已删除的定义

请求

GET https://graph.microsoft.com/beta/admin/resourcePolicy/deletedItems/definitions/require_application_name
Accept: text/plain

响应

HTTP/1.1 200 OK
Content-Type: text/plain
ETag: "972dd856-91ff-4539-be09-50ea8235b76e"

package graph.require_application_name["1.0.0"]

__metadata__ := {
  "title": "Require an application name",
  "description": "Require applications to have a display name",
  "category": "identityAndTenant",
  "selector": {
    "resourceName": "microsoft.graph.application",
    "operations": ["create", "updateOrUpsert"]
  }
}

default deny := {"result": false, "reasons": []}

deny := {"result": true, "reasons": ["A display name is required."]} if {
  object.get(input.resource, "displayName", "") == ""
}