Microsoft Graph API-powershell中的应用程序-禁止响应

Microsoft Graph API-powershell中的应用程序-禁止响应,powershell,azure-active-directory,microsoft-graph-api,Powershell,Azure Active Directory,Microsoft Graph Api,我正在尝试使用powershell 5.1进行Microsoft Graph API调用。我已经注册了这个应用程序。我使用AppID和secret获得授权承载令牌。然后构造API请求。安全/事件终结点仅返回禁止响应 我的呼叫脚本如下所示: # Define AppId, secret and scope, your tenant name and endpoint URL $AppId = [myAPPID] $AppSecret = [myAPPSecret] $Scope = "https

我正在尝试使用powershell 5.1进行Microsoft Graph API调用。我已经注册了这个应用程序。我使用AppID和secret获得授权承载令牌。然后构造API请求。安全/事件终结点仅返回禁止响应

我的呼叫脚本如下所示:

# Define AppId, secret and scope, your tenant name and endpoint URL
$AppId = [myAPPID]
$AppSecret = [myAPPSecret]
$Scope = "https://graph.microsoft.com/.default"
$TenantName = "[mytenant].onmicrosoft.com"

$Url = "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token"

# Add System.Web for urlencode
Add-Type -AssemblyName System.Web

$Body = @{
        client_id = $AppId
        client_secret = $AppSecret
        scope = $Scope
        grant_type = 'client_credentials'
}

# Splat the parameters for Invoke-Restmethod for cleaner code
$PostSplat = @{
    ContentType = 'application/x-www-form-urlencoded'
    Method = 'POST'
    # Create string by joining bodylist with '&'
    Body = $Body
    Uri = $Url
}

$Request = Invoke-RestMethod @PostSplat

$Header = @{
    Authorization = "$($Request.token_type) $($Request.access_token)"
}

$Uri = "https://graph.microsoft.com/v1.0/security/events"

$SecurityAlertsRequest = Invoke-RestMethod -Uri $Uri -Headers $Header -Method Get -ContentType "application/json"

只是想看看我是否错过了一些明显的东西。是否有任何其他原因会对此配置以“禁止”响应?

您已授予该应用的委派权限。 只有当有用户登录到您的应用程序并且您获得访问令牌以代表他们时,这些才适用


您需要在Azure AD中将应用程序权限授予您的应用程序。

您已将委派权限授予该应用程序。 只有当有用户登录到您的应用程序并且您获得访问令牌以代表他们时,这些才适用

您需要向Azure AD中的应用程序授予应用程序权限