【发布时间】:2018-11-03 09:11:22
【问题描述】:
我正在尝试编写一个 PowerShell 脚本,让用户授权 Azure Active Directory 应用程序代表他们执行操作。
遵循授权代码授予流程documentation from Microsoft。我正在使用以下行调用授权端点:
Invoke-WebRequest -Method GET -Uri "https://login.microsoftonline.com/$tenantId/oauth2/authorize?client_id=$applicationId&response_type=code&redirect_uri=$redirectUri&response_mode=query&resource=$resource&state=09876"
它同时在 PowerShell 中返回响应并同时在我的默认浏览器上打开一个网页。
下面是响应的样子:
StatusCode : 200
StatusDescription : OK
Content :
<!DOCTYPE html>
<html dir="ltr" class="" lang="en">
<head>
<title>Sign in to your account</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-eq...
RawContent : HTTP/1.1 200 OK
Pragma: no-cache
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
x-ms-request-id: ed3ee9de-ccc4-47ea-ac52-087b...
Forms : {}
Headers : {[Pragma, no-cache], [Strict-Transport-Security, max-age=31536000; includeSubDomains],
[X-Content-Type-Options, nosniff], [X-Frame-Options, DENY]...}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 22592
浏览器中显示的网页被重定向到https://login.microsoftonline.com/cookiesdisabled,并显示以下消息:
我们无法让您登录 您的浏览器当前设置为阻止 cookie。您需要允许 cookie 使用此服务。 Cookie 是存储在您计算机上的小型文本文件,当您登录时会告诉我们。要了解如何允许 Cookie,请查看您的网络浏览器中的在线帮助。
总而言之,它不起作用!
请注意,我的浏览器中启用了 cookie,如果我从网络浏览器调用网络请求,它将正常工作。
我做错了什么?以及如何使用 PowerShell 向用户提示对话框并在 PowerShell 中接收回授权码响应?
谢谢。
【问题讨论】:
标签: powershell azure oauth-2.0 azure-active-directory