Office 365图Graph API 400错误请求

时间:2018-06-19 22:51:33

标签: powershell office365

我正在使用以下模块

https://psmsgraph.readthedocs.io/en/latest/

尝试传递以下$AuthCode

@{AuthCodeCredential=System.Management.Automation.PSCredential; ResultURL=https://localhost/?code=AQABAAIAAADX8GCi6Js6SK82TsD2Pb7rsheCqji8MFS19OlJ8dFqrxjfk9
TTz9sPIyErZzaOD45niqpvZz5vnViz6tAU2BoKGQfX1-tW781HweG4jHoznO09NQpJDTiDl8i8yv6O_xT7RqUzitK59gssyyOPjc-4k5BEVa0hPJpXJCFHwUokCRzRBo4tS6Frv5XbxQkR8huM2Y1pK8o6Mq
PxKMPxGSfcrzS7vRjh-99qeD-DsXbc1eGGh1AQsWfTl1wqUlUcLJnMstF6ePnxIuM2XpRbFo7kYZ-5md7xrSD4Fw9L02NQjA-7TuOFM_4xXeM6gKL9SG8iW9Hxow0aNUm8ZtsLPBvAPJWJVrzhglVqz9pmmV
c9nAD1ujn2au2J9OlT_zwlXsJyHb3Gf4GqjQraYm91dV_7HzRj92LlCwjAwPypXFAhllYXPflUCgUtUYvvJfxSVS5Nc1meRUXlk-qedwv1RpbbT-pNHMPUuJmbEEM-sxAY1Oxg9GC93oH3S-rSMF5kZydr40
UOFwlnRIp10Vti6VA3IAA&session_state=25644a38-645f-4c8b-a6d9-be01838fa932; Application=Guid: 91ba65d8-2aa9-4771-9f9c-d05756da6931 Name: PowerShell Module; Au
thCodeBaseURL=https://login.microsoftonline.com/<mytenantid>/oauth2/authorize; Response=System.Collections.Hashtable; Issued=19/06/2
018 6:46:38 PM; Success=System.Management.Automation.PSScriptProperty; Expires=System.Management.Automation.PSScriptProperty; IsExpired=System.Management.Au
tomation.PSScriptProperty}

我收到以下错误:

Get-GraphOauthAccessToken : The remote server returned an error: (400) Bad Request.
At line:24 char:21
+ ... cessToken = Get-GraphOauthAccessToken -BaseURL 'https://login.microso ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WebException
    + FullyQualifiedErrorId : System.Net.WebException,Get-GraphOauthAccessToken

这是完整的代码:

Import-Module -name 'PSMSGraph'
#In the credential prompt, provide your application's Client ID as the username and Client Secret as the password
$ClientCredential = Get-Credential
$GraphAppParams = @{
    Name = 'PowerShell Module'
    ClientCredential = $ClientCredential
    RedirectUri = 'https://localhost/'
    Tenant = '<mytenantid>'

}
$GraphApp = New-GraphApplication @GraphAppParams
Write-Host "Application"
Write-Host $GraphApp
Write-Host "-------------"
# This will prompt you to log in with your O365/Azure credentials. 
# This is required at least once to authorize the application to act on behalf of your account
# The username and password is not passed back to or stored by PowerShell.
$AuthCode = Get-GraphOauthAuthorizationCode -BaseURL 'https://login.microsoftonline.com/<mytenantid>/oauth2/authorize' -Application $GraphApp
Write-Host 'Authorization Code'
Write-Host $AuthCode
Write-Host '----------------'
# see the following help for what resource to use. 
# get-help Get-GraphOauthAccessToken -Parameter Resource
$GraphAccessToken = Get-GraphOauthAccessToken -BaseURL 'https://login.microsoftonline.com/<mytenantid>/oauth2/token' -AuthenticationCode $AuthCode -Resource "https://graph.microsoft.com"
$GraphAccessToken | Export-GraphOAuthAccessToken -Path 'c:\Temp\AccessToken.XML'

我的问题是,我可以连接许多URL,并且关于我的租户ID的想法相互矛盾,因此我不确定我是否正确。这是针对公司而非单个用户的。

编辑-最终,我要做的就是提取在https://portal.office.com/adminportal/home#/reportsUsage中可见的报告

0 个答案:

没有答案