通过 Graph API 删除 Azure AD 应用程序
Deleting Azure AD Applications via Graph API
我的任务是编写一些 powershell 脚本来自动执行 Azure AD 租户中的一些基本操作。我已经成功地添加和删除了用户和域,并且我已经通过 Azure Graph 添加了新的应用程序 API,但是我没有成功删除应用程序。
这方面的文档似乎很少,而且我找不到任何人这样做的例子。根据支持操作下的应用程序参考,应该可以 (https://msdn.microsoft.com/library/azure/ad/graph/api/entity-and-complex-type-reference#applicationentity):
Supported Operations
The following operations are supported on applications (HTTP methods are >listed in parentheses):
create (POST)
read (READ)
update (PATCH)
delete (DELETE)
那么 URI 应该是什么样的?我找不到直接的答案,但要删除用户,您可以使用:
https://graph.windows.net/myorganization/users/{user_id}[?api-version]
所以,我想尝试类似的方法来删除应用程序:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_id}?api-version=1.6
如果这是正确的,那么应用程序 ID 是什么?客户端 ID 和 App ID URI 对我来说最有意义,但到目前为止,这些和应用程序名称都不适合我。会不会是格式问题?根据我的尝试,我会遇到不同的错误。
应用程序名称:
https://graph.windows.net/company.onmicrosoft.com/applications/application4?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4'."},"values":null}}
客户端 ID(此处清零):
https://graph.windows.net/company.onmicrosoft.com/applications/00000000-0000-0000-0000-000000000000?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":"code":"Request_ResourceNotFound","message":{"lang":"en","value":"Resource '00000000-0000-0000-0000-000000000000' does not exist or one of its queried reference-property objects are not present."}}}
App ID URI - 不确定如何添加它。也许我需要一些编码?尝试了两种方式:
https://graph.windows.net/company.onmicrosoft.com/applications/application4.company.com?api-version=1.6
产生
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4.company.com'."},"values":null}}
和
https://graph.windows.net/company.onmicrosoft.com/applications/https://application4.company.com?api-version=1.6
我怀疑编码可能会发挥作用。目前它只是产生
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message"{"lang":"en","value":"Bad request. Please fix the request before retrying."}}}
知道我哪里出错了吗?
您需要使用objectId。除了客户端 ID 之外,应用程序(与所有 AAD 对象一样)还有一个 objectId。
所以 URL 应该是:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_objectId}?api-version=1.6
我的任务是编写一些 powershell 脚本来自动执行 Azure AD 租户中的一些基本操作。我已经成功地添加和删除了用户和域,并且我已经通过 Azure Graph 添加了新的应用程序 API,但是我没有成功删除应用程序。
这方面的文档似乎很少,而且我找不到任何人这样做的例子。根据支持操作下的应用程序参考,应该可以 (https://msdn.microsoft.com/library/azure/ad/graph/api/entity-and-complex-type-reference#applicationentity):
Supported Operations
The following operations are supported on applications (HTTP methods are >listed in parentheses):
create (POST)
read (READ)
update (PATCH)
delete (DELETE)
那么 URI 应该是什么样的?我找不到直接的答案,但要删除用户,您可以使用:
https://graph.windows.net/myorganization/users/{user_id}[?api-version]
所以,我想尝试类似的方法来删除应用程序:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_id}?api-version=1.6
如果这是正确的,那么应用程序 ID 是什么?客户端 ID 和 App ID URI 对我来说最有意义,但到目前为止,这些和应用程序名称都不适合我。会不会是格式问题?根据我的尝试,我会遇到不同的错误。
应用程序名称:
https://graph.windows.net/company.onmicrosoft.com/applications/application4?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4'."},"values":null}}
客户端 ID(此处清零):
https://graph.windows.net/company.onmicrosoft.com/applications/00000000-0000-0000-0000-000000000000?api-version=1.6
产量
Invoke-RestMethod : {"odata.error":"code":"Request_ResourceNotFound","message":{"lang":"en","value":"Resource '00000000-0000-0000-0000-000000000000' does not exist or one of its queried reference-property objects are not present."}}}
App ID URI - 不确定如何添加它。也许我需要一些编码?尝试了两种方式:
https://graph.windows.net/company.onmicrosoft.com/applications/application4.company.com?api-version=1.6
产生
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"Invalid object identifier 'application4.company.com'."},"values":null}}
和
https://graph.windows.net/company.onmicrosoft.com/applications/https://application4.company.com?api-version=1.6
我怀疑编码可能会发挥作用。目前它只是产生
Invoke-RestMethod : {"odata.error":{"code":"Request_BadRequest","message"{"lang":"en","value":"Bad request. Please fix the request before retrying."}}}
知道我哪里出错了吗?
您需要使用objectId。除了客户端 ID 之外,应用程序(与所有 AAD 对象一样)还有一个 objectId。
所以 URL 应该是:
https://graph.windows.net/company.onmicrosoft.com/applications/{application_objectId}?api-version=1.6