【问题标题】:Azure Cloud PowerShell return output got replaced with dot dot dotAzure Cloud PowerShell 返回输出已替换为 dot dot dot
【发布时间】:2021-05-25 11:04:33
【问题描述】:

我正在使用 Azure Cloud PowerShell 通过使用获取访问令牌

$postParams = @{"client_id"="xxx3f7c-2a52-4be8-a7cf-1b499ee58d4d";
"scope"="https://graph.microsoft.com/.default";
"client_secret"="xxxL66S-h4pMnIPZrR7-..9L7NnyU9B4";
"grant_type"="client_credentials"
}

Invoke-WebRequest -Uri https://login.microsoftonline.com/xxxaab-164a-4603-b614-9405173c5351/oauth2/v2.0/token -Method POST -Body $postParams

但是,返回的标记被截断并替换为 ... 而没有结束内容属性的引号。

StatusCode        : 200
StatusDescription : OK
Content           : {"token_type":"Bearer","expires_in":3599,"ext_expires_in":3599,"access_token":"eyJ0eXAiOiJKxxxiLCJub25jZSI6IlV3YTF4NWJYZnE2V3hOS211TFVqNEJYaTNIZGVKNExLeEZSSFMxVGs4eWsiLCJhbGciOiJSUzI1NiIsIng1dCI6Im5Pb…
RawContent        : HTTP/1.1 200 OK
                    Cache-Control: no-store, no-cache
                    Pragma: no-cache
                    Strict-Transport-Security: max-age=31536000; includeSubDomains
                    X-Content-Type-Options: nosniff
                    P3P: CP="DSP CUR OTPi IND OTRi ONL FIN…
Headers           : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Strict-Transport-Security, System.String[]], [X-Content-Type-Options, System.String[]], [P3P, System.String[]], [x-ms-request-id, System.String[]],
                    [x-ms-ests-server, System.String[]], [Set-Cookie, System.String[]], [Date, System.String[]], [Content-Type, System.String[]], [Expires, System.String[]], [Content-Length, System.String[]]}
Images            : {}
InputFields       : {}
Links             : {}
RawContentLength  : 1507
RelationLink      : {}

内容属性以 m5Pb... 结尾,不完整。如何从 Azure Cloud PowerShell 获取完整的令牌内容?

【问题讨论】:

  • 如果将请求保存到变量然后调用Content 属性,它是否仍然被截断? $req = Invoke-WebRequest -Uri http.....$req.Content
  • 截断仅在输出中,只是因为它不适合显示。在$req.Content | ConvertFrom-Json 里面是完整的。
  • 您好,您可以accept作为结束话题的答案。

标签: azure powershell oauth-2.0 azure-active-directory microsoft-graph-api


【解决方案1】:

@Santiago Squarzon 说的对,你需要将请求保存到一个变量中,然后调用Content 属性,它会返回完整的访问令牌。

$postParams = @{"client_id"="ab717ac0-4abe-449d-aeb3-685c86c22xxx";
"scope"="https://graph.microsoft.com/.default";
"client_secret"="U5BPXYvLy2oO.5JE.Y.Ty3d~7b281W5xxx";
"grant_type"="client_credentials"
}

$req=Invoke-WebRequest -Uri https://login.microsoftonline.com/e4c9ab4e-bd27-40d5-8459-230ba2a757fb/oauth2/v2.0/token -Method POST -Body $postParams

$req.Content

【讨论】:

    猜你喜欢
    • 2016-03-18
    • 2017-08-22
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2013-01-20
    • 2020-03-26
    • 2021-07-09
    相关资源
    最近更新 更多