gpt4 book ai didi

azure - 使用 Microsoft Graph API 和 REST 方法从 Azure 门户应用程序注册中检索应用程序所有者

转载 作者:行者123 更新时间:2023-12-03 06:12:37 24 4
gpt4 key购买 nike

我正在尝试通过 PowerShell 脚本使用 Microsoft Graph API 和 REST 方法从 list 下的 Azure 门户应用程序注册中检索应用程序所有者。我使用服务主体帐户(客户端 key )、租户和客户端 ID(应用 ID)对 Graph API 进行身份验证。

以下是获取特定应用信息的代码:

Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/applications?$filter=appId eq 'appIdhere'" -Headers $headers -Method GET

我正在使用以下请求 header 和正文:

$requestBody = @{
"grant_type" = "client_credentials"
"client_id" = $clientId
"client_secret" = $clientSecret
"scope" = "https://graph.microsoft.com/.default"
}

$headers = @{
Authorization = "Bearer $accessToken"
}

但是,上面的代码仅适用于图表。请参阅下面的文档。 (我使用了/applications 端点,它仍然适用于下面的引用)Microsoft Graph API - 列出服务主体的所有者

我想使用上述 URL 访问应用注册 Azure 门户下的应用程序 list ,但在使用 PowerShell ISE 中的 Invoke-RestMethod 时,该 URL 会从 Azure 门户检索所有应用程序,而不是仅从 URL 检索指定的应用程序.

我想请求有关如何检索此 URL 下的指定信息的帮助:“https://graph.microsoft.com/v1.0/applications?$filter=appId eq 'f059f748-6b42-46ec-8d5b- 23a0fee126ee'”。预先感谢那些愿意提供帮助的人。

最佳答案

我注册了一个 Azure AD 应用程序并添加了 API 权限,如下所示:

enter image description here

现在,我将以下用户添加为应用程序的应用程序所有者:

enter image description here

要使用 Microsoft Graph API 从 list 下的 Azure 门户应用程序注册中检索应用程序所有者,您可以使用以下查询:

GET https://graph.microsoft.com/v1.0/applications/<AppID>/owners

要通过使用 PowerShell 调用 REST API 获得相同的结果,您可以执行以下脚本:

$requestbody = @{
client_id = "ClientID"
client_secret = "ClientSecret"
scope = "https://graph.microsoft.com/.default"
grant_type = 'client_credentials'
}
$AccessToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/TenantID/oauth2/v2.0/token" -Method Post -Body $requestbody
$token = $AccessToken.access_token
$query = "https://graph.microsoft.com/v1.0/applications/AppID/owners"
(Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $query -Method Get).value | select id

当我运行脚本时,我在响应中获得了应用程序所有者的对象 ID,如下所示:

enter image description here

引用: List owners - Microsoft Graph v1.0 | Microsoft

关于azure - 使用 Microsoft Graph API 和 REST 方法从 Azure 门户应用程序注册中检索应用程序所有者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76578185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com