了UiApp:对于非Gmail用户永久登录(UiApp: Persistent login for

2019-09-26 22:25发布

我试图实现需要用户登录和使用建立我们的系统上的帐户谷歌Apps脚本的Web服务。

用户不一定有一个Gmail帐户,并且不应该被要求创建一个。

Web服务必须运行使用的脚本所有者,因为必须为它能够写入到电子表格和其他资源,没有共享的写权限。

我已成功地实现登录屏幕,具有相当强的安全 - 但我现在遇到的问题是,用户必须重新登录每次访问时间,即使他们打的刷新按钮。

任何想法如何实现这一点? 是否有某种方式来存储用户的浏览器cookie中,包含会话ID? 或者是有一些其他的可以工作的方法?

提前致谢!

玩笑

Answer 1:

这是一个很老的文章,但因为有一个解决方案,我认为这是更好地表现出来,以帮助人们同样需要

嗨乔希,

我已经开发了这样的系统也的确是一个办法做到这一点。

事实上,你可以开发类似系统的Cookie使用PrivateCache类:CacheService.getPrivateCache()。

如果用户重新载入页面或关闭它的工作原理。

但是这种解决方案,当你关闭浏览器就不可能再检索信息。

下面是我用它来阻止你都强调了问题的功能

随意适应他们

function getCookie(){
  var cache=CacheService.getPrivateCache();
  var cached=cache.get("UserCookie");
  if(cached!=null){
    return Utilities.jsonParse(cached);
  }
  return -1;
}

function createCookie(data){
  var cache=CacheService.getPrivateCache();
  cache.put("UserCookie",Utilities.jsonStringify(data),1800); 
}

function removeCookie(){
  var cache=CacheService.getPrivateCache();
  cache.remove("UserCookie"); 
}

另一种方法是使用UserProperties。 在这种情况下,如果你关闭浏览器,将工作,甚至......我刚刚试了一下

因此功能,以使用的是:

function getCookie(){
  var cached=UserProperties.getProperty('UserCookie');
  if(cached!=null){
    return Utilities.jsonParse(cached);
  }
  return -1;
}

function createCookie(data){
    UserProperties.setProperty('UserCookie',Utilities.jsonStringify(data));
}

function removeCookie(){
  UserProperties.deleteProperty("UserCookie"); 
}

我希望这将帮助任何人...

干杯

萨科



Answer 2:

永久登录,也无法通过Google Apps脚本作为Google Apps脚本是无法和Google Apps脚本仅旨在与谷歌帐户的工作饼干等浏览器对象进行交互。



文章来源: UiApp: Persistent login for non-gmail users