【问题标题】:Vouch Proxy with UrlFetchApp使用 UrlFetchApp 验证代理
【发布时间】:2021-10-04 13:05:59
【问题描述】:

我的组织正在使用Vouch Proxy 来保护子域。我希望能够使用类似 oauth 令牌的东西来登录,类似于以下内容。

我希望有人可以使用上面的链接为我指明正确的方向。

有没有办法创建和保留 cookie 以发出 UrlFetchApp 请求?

气体:

var token = ScriptApp.getOAuthToken();
var header = {"Authorization":"Bearer " + token};

var options = {
"method":"GET",
"headers": header,
"muteHttpExceptions": true
};

var url = 'url'

var response =UrlFetchApp.fetch(url, options);

Logger.log(response.getResponseCode()); //returns 200
Logger.log(response.getContentText()); // returns 'sign in with Google' HTML

编辑

以下内容还返回“使用 Google 登录”HTML。

function fetchUrlWithCookie() {
  var url = 'https://vouch.oursites.com/login?url=https://private.oursites.com';
  var response = UrlFetchApp.fetch(url, {
    muteHttpExceptions: true,
    followRedirects: false,
    headers: {"Authorization":"Bearer " + ScriptApp.getOAuthToken()}
  });
  var cookie = response.getAllHeaders()['Set-Cookie']; //Get cookie from header 
  response = UrlFetchApp.fetch(url, {
    muteHttpExceptions: true,
    followRedirects: true,
    headers: {
      Cookie: cookie, //send the cookie we got as header
    },
  });
  Logger.log(response.getContentText());
}

我也尝试过使用安全性较低的应用密码的基本身份验证,结果相同。

【问题讨论】:

  • Cookie 只是一个标题。您可以发送任何 cookie 作为标头。见stackoverflow.com/questions/53660031
  • @TheMaster 我用代码 sn-p 编辑了我的问题。也许我不明白如何有效地获得正确的细节以进行身份​​验证。
  • 这不是复制粘贴作业。您需要了解每条线路的作用以及担保代理在每个步骤中的作用。话虽如此,在初步浏览时,使用浏览器誓言反对使用this library 的担保代理似乎是获取资源的可能方式。尽管如此,我还是找不到从“回调”访问 cookie 的方法 或者,您可以尝试手动重新创建其担保代理流程中的每个步骤。也许在他们的 github 中创建一个问题。 This issue 似乎相关。

标签: nginx google-apps-script oauth nginx-reverse-proxy urlfetch


【解决方案1】:

在这里确认代理开发

我在这里没有足够的业力来发表评论,但我想提出这是 VP 存储库上的 GitHub 问题...

https://github.com/vouch/vouch-proxy/issues/432

我们即将找到解决方案,但仍在收集更多信息。

【讨论】:

  • After the user authenticates with the IdP (with username and password or otherwise) the user is forwaded back to VP at which point VP issues its own token. VP 究竟要寻找什么来知道用户已经登录到 google(idP)?如果是 cookie,我们可以通过从服务器端获取来模拟经过身份验证的 google cookie。
  • VP 通过标准 OAuth/OIDC 流程将 Authn 会话移交给 IdP,该流程取决于称为 state 变量的随机数。在 IdP (Google) 成功登录后,用户将使用state 和可用于交换完整令牌的code 转发回 VP。oauth.com/oauth2-servers/accessing-data/…
  • 所以,如果我们以某种方式拦截codestate,我们可以从vp 获取jwt cookie..对吗?或者是否有任何其他安全检查,例如检查origin?我想我是在问 OP 是否可以拦截 oauth 流,并看到所需的 Google 凭据。
  • Identity token 似乎是最官方的方法。您或您是否有计划支持身份令牌?
  • @TheMaster VP 不支持 Google 的身份令牌,并且不在任何路线图中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-05
  • 1970-01-01
  • 1970-01-01
  • 2019-09-30
  • 2010-10-17
相关资源
最近更新 更多