Google Apps Script Web App在外部网站上进行身份验证 [英] Google Apps Script Web App authenticate on external website

查看:187
本文介绍了Google Apps Script Web App在外部网站上进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现用于登录网站的Google Apps脚本应用,然后,如果该网站上的身份验证过程成功,则用户应该在google脚本侧边栏中收到一条消息.

I need to implement a Google Apps Script app that is used to login on a website and then if the authentication process succeed on that website the user should receive a message in the google script sidebar.

例如:用户输入电子邮件和密码,然后按登录"按钮,然后在凭据正确的情况下登录网站.

For example: the user enters his email and password and then he press the Login button, then he should be logged in on the website if the credentials are correct.

让我知道是否需要提供更多详细信息...我是Google Apps脚本的新手,在此登录过程中确实需要一些帮助.谢谢!

Let me know if I need to provide more details on this... I am new with Google Apps Script and I really need some help with this login process. Thank you!

我尝试实现以下代码,但执行login函数时收到以下错误消息:

I tried to implement the following code but I receive the following error message when executing the login function:

https://example.com/login 的请求失败,返回了代码405.

Request failed for https://example.com/login returned code 405.

HTML文件:

<div class="form-auth">
  <label class="inline">username</label>
  <input type="text" placeholder="Insert Email"/>
</div>
<div class="form-auth">
  <label class="inline">password</label>
  <input placeholder="Insert Password"/>
</div>
<button class="btn-default">Login</button>

Google脚本文件:

Google Script file:

function onOpen() {
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .createMenu('Menu')
      .addItem('Show sidebar', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('login')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setTitle('SDR Tag Governance')
      .setWidth(300);
  SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
      .showSidebar(html);
}

function login() {
  var payload =
   {
     "username" : "myEmail@domain.com",
     "password" : "myPassword",
   };
  var options =
   {
     "method" : "post",
     "payload" : payload,
     "followRedirects" : false
   };
  var login = UrlFetchApp.fetch("https://example.com/login" , options);
  var sessionDetails = login.getAllHeaders()['Set-Cookie'];
}

推荐答案

通过添加标题选项来解决此问题:

Fixed this by adding headers option:

  var headers = {
    'Connection':'keep-alive',
    'Content-Type':'application/json;charset=utf-8',
    'Accept':'application/json, text/plain, */*',
    'Cookie':'...',
  }

这篇关于Google Apps Script Web App在外部网站上进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆