我的问题是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。
发布于 2016-12-05 04:19:16
根据菲利普的评论,请注册您自己的应用程序。据我所知,您试图对powershell客户端的ID执行的操作不会起作用,增量/动态同意ADAL 3.13也不会起作用。MSAL (一个新的身份验证客户端库)确实支持增量同意,你可以尝试这样做,但MSAL还处于预览阶段(你需要在apps.dev.microsoft.com上注册你的应用)。或者,如果你想继续使用ADAL,你可以使用Azure门户在portal.azure.com上注册你的应用,方法是搜索应用注册刀片,在那里你将想要注册一个本地客户端应用,并请求用户权限,邮件和任何其他你在微软图形中需要的东西。
顺便说一句,出于兴趣,你想在这里做什么?您是否正在尝试为Outlook和Microsoft Graph创建PowerShell客户端?如果我们提供Microsoft Graph PowerShell客户端,您会感兴趣吗?如果是这样,请在UserVoice上请求。
希望这能帮上忙
https://stackoverflow.com/questions/40929187
复制相似问题