UiApp:非Gmail用户的永久登录 [英] UiApp: Persistent login for non-gmail users

查看:43
本文介绍了UiApp:非Gmail用户的永久登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施一项Google Apps脚本网络服务,该服务要求用户使用我们系统上设置的帐户登录.

I am attempting to implement a Google Apps Script web service which requires users to log in using an account set up on our system.

用户不一定要有一个Gmail帐户,也不需要创建一个.

The users will not necessarily have a gmail account, and should not be required to create one.

该Web服务必须以脚本所有者的身份运行,因为它必须能够写入电子表格和其他没有共享写许可权的资源.

The web service must run using as the script owner, as it is necessary for it to be able to write to a spreadsheet and other resources which do not have shared write permission.

我已经设法实现了登录屏幕,并且具有相当强的安全性-但是我现在遇到的问题是,用户每次访问时都必须重新登录,即使他们单击了刷新按钮也是如此.

I have managed to implement the login screen, with reasonably strong security -- but the problem I encounter now is that users must log back in every time they visit, and even if they hit the refresh button.

关于如何实现此目标的任何想法? 有什么方法可以在用户浏览器中存储包含会话ID的cookie? 还是有其他可行的方法?

Any ideas on how to implement this? Is there some way to store a cookie in the users browser, containing a session id? Or is there some other method which can work?

提前谢谢!

乔什

推荐答案

这是一篇很老的文章,但是由于有解决方案,我认为最好将其展示给有类似需求的人以帮助

This is a very old post but as there is a solution, I think it is better to show it to help people with a similar need

乔希,你好

我已经开发了这样的系统,确实有一种方法可以做到这一点.

I have developed such a system and there is indeed a way to do this.

您确实可以开发使用Cookie的系统,例如使用PrivateCache类:CacheService.getPrivateCache().

You can indeed develop a cookie like system that is using the PrivateCache class: CacheService.getPrivateCache().

如果用户重新加载页面或关闭页面,此功能就起作用.

It works if the user reload the page or close it.

但是,使用此解决方案,当您关闭浏览器时,将无法再检索信息.

However with this solution when you close your browser it will not be possible to retrieve the information anymore.

这是我用来防止您强调的问题的功能

Here are the functions that I use to prevent the problem you have underlined

随时适应它们

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.在这种情况下,即使您关闭浏览器也可以使用...我刚刚尝试过

Another way would be to use UserProperties. In this case it will work even if you close your browser... I just tried it

因此要使用的功能是:

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"); 
}

我希望它将对任何人有帮助...

I hope it will help anyone...

欢呼

尼古拉斯

这篇关于UiApp:非Gmail用户的永久登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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