2

我需要通过 Powershell访问这个主站点https://www.truecaller.com/search/eg/xxxx 。

我使用表单身份验证为 Invoke-WebRequest 编写了许多 PowerShell 脚本,但这次网站使用来自 Google 或 Microsoft 的外部身份验证。

从谷歌搜索中,我注意到我必须先获取访问授权码。

该站点从google API配置为Web应用程序而不是桌面应用程序的问题,因此拒绝在网页上给我授权码。

我不拥有该网站,因此我无法从网站或身份验证方面进行任何更改。

通常,当我在浏览器上打开主站点并选择从 Google 进行身份验证时,它会将我重定向到

https://accounts.google.com/o/oauth2/v2/auth/identifier?response_type=code&client_id=22378802832-klpcj5dosalhnu0vshg3hjm9qgidmp8j.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fwww.truecaller.com%2Fauth%2Fgoogle%2Fcallback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts.readonly&flowName=GeneralOAuthFlow

然后在身份验证后,它将我重定向回主站点

我正在使用下面的代码来捕获授权代码,以便稍后在另一个命令中使用以获取访问令牌,然后调用 webrequest 到主站点。

$clientId         = "22378802832-klpcj5dosalhnu0vshg3hjm9qgidmp8j.apps.googleusercontent.com"
$redirect_uri1    = "https%3A%2F%2Fwww.truecaller.com%2Fauth%2Fgoogle%2Fcallback"
$redirect_uri2    = "urn:ietf:wg:oauth:2.0:oob"
$scopes           = "https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/contacts.readonly"
Start-Process       "https://accounts.google.com/o/oauth2/v2/auth?client_id=$clientId&scope=$scopes&access_type=offline&response_type=code&redirect_uri=$redirect_uri1"   

当我使用$redirect_uri1

谷歌在网上询问我是否允许应用程序访问我的帐户后,它会正常访问网站并且没有给我授权码,因为重定向 URL 是 https://www.truecaller.com/auth/google/callback

当我使用$redirect_uri2

Google 拒绝完成身份验证过程,因为我使用 URL 重定向桌面 URL,并且此 clientID 配置为使用 Web 重定向,我面临以下错误。 在此处输入图像描述

我的问题是,我如何在这个通过 OAuth 使用外部身份验证的主网站上使用 Invoke-WebRequest 或 Invoke-RestMethod,这是双重的吗?

4

0 回答 0