【发布时间】:2016-12-05 04:19:16
【问题描述】:
我的问题是 ADAL for GRAPH API 中的“范围或权限”。
我正在使用 ADAL 3.13,并创建了以下脚本:
$adal = "C:\Users\filippog\Desktop\ADAL\_Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "C:\Users\filippog\Desktop\ADAL\_Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
[System.Reflection.Assembly]::LoadFrom($adal)
[System.Reflection.Assembly]::LoadFrom($adalforms)
[string] $adTenant = "****"
[string] $clientId = "1950a258-227b-4e31-a9cf-717495945fc2" #id client of powershell
[string] $resourceAppIdURI = "https://graph.windows.net/"
[string] $authority = "https://login.microsoftonline.com/$adTenant"
[uri] $redirectUri = "urn:ietf:wg:oauth:2.0:oob" #redirect urPowerShell - i of powershell
[string] $resourceURI = 'https://graph.microsoft.com/'
[string] $scope = "scope=mail.read"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority #,$false
$PromptBehavior = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always
$platformParam = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList $PromptBehavior
$userId = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier" -ArgumentList "****", "OptionalDisplayableId"
$authResult = $authContext.AcquireTokenAsync($resourceUri, $clientId, $redirectUri, $platformParam, $userId, $scope)
$AuthHeader=$authResult.result.CreateAuthorizationHeader()
$headers = @{
"Authorization" = $AuthHeader
"Content-Type" = "application/json"
}
Invoke-RestMethod -Headers $headers -Uri https://graph.microsoft.com/v1.0/me/messages -Method Get
我的问题是,当我执行脚本并调用图形时(例如,graph/v1.0/me 它可以工作,但是当我调用 graph/v1.0/me/messages 时,脚本返回 error 403。
【问题讨论】:
-
您真的不应该使用不属于您自己的应用程序的客户端 ID。注册自己的本地客户端应用程序非常容易,而且您将获得额外的优势(例如,您可以在登录提示中控制命名和品牌)。
-
PowerShell 客户端 ID 没有邮件消息的范围。
标签: api powershell adal microsoft-graph-api