2016-12-02 53 views
0

我的问题是ADAP for GRAPH API中的“SCOPE or PERMISSION”。ADAL 3.13 - 图表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

+0

你真的不应该使用非你自己的应用程序的客户端ID。注册自己的本地客户端应用程序非常简单,您将获得更多优势(例如,您可以在登录提示中控制命名和品牌)。 –

回答

0

每Philippe的评论,请注册自己的应用程序。 你正在尝试使用PowerShell的客户端的ID做不会,据我知道的工作,也不会增量/动态同意ADAL 3.13。MSAL(一个新的auth客户端库瑞利)确实支持增量同意,你可以尝试,但MSAL预览(你需要在apps.dev.microsoft.com注册你的应用程序)。或者,如果您想继续使用ADAL,则可以使用Azure门户在portal.azure.com上注册您的应用程序,方法是搜索应用程序注册刀片,在其中注册本地客户端应用程序,然后向用户,邮件和您在Microsoft Graph中需要的任何其他内容。

顺便说一句 - 出于兴趣,你想在这里做什么?您是否想要为Outlook和Microsoft Graph创建PowerShell客户端?如果我们提供了Microsoft Graph PowerShell客户端,您会对此感兴趣吗?如果是这样,请在UserVoice上申请。

希望这会有所帮助,