Google应用程序脚本网络应用程序,如何创建登录按钮? [英] Google app script web app, how to create a login button?

查看:81
本文介绍了Google应用程序脚本网络应用程序,如何创建登录按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Google云端硬盘中创建了由Google电子表格支持的脚本,并将其发布为网络应用,并设置了以我的身份执行应用"和有权访问该应用的用户:任何人,甚至是匿名用户".主页提供电子表格中的html内容.

I have create script backed by a Google Spreadsheet in Google Drive and published it as a web app, setting "Execute the app as: me" and "Who has access to the app: Anyone, even anonymous". The main page serves html content from the spreadsheet.

基本功能是:随机互联网用户"可以查看一些信息,而使用Google帐户登录的用户也可以提交信息.

The basic functionalities are: a "random internet user" is able to see some informations, while an user logged with his Google Account is able to submit information as well.

问题是-如果我将权限设置为任何人",则首先将人们重定向到标准google登录页面,并且登录后必须接受脚本权限.完成此操作后,只要您使用自己的google帐户登录,导航到该网络应用程序将提供已登录用户"版本.

The issues is - if I set the permission to "anyone" people are first redirected to the standard google login page, and once logged in have to accept the script permissions. Once that's done, navigating to the web app will give the "logged in user" version as long as you are logged in with your google account.

但是-如果将Web应用程序设置为允许匿名用户",则似乎没有任何(至少很明显的方式)允许匿名用户登录并接受应用程序权限.

However - if the web app is set to allow "anonymous users" there doesn't seem to be any (at least obvious way) to allow anonymous users to login and accept the app permissions.

到目前为止我一直在尝试:

What I have tried until now:

  • 如果该Web应用要求用户登录,则指向Google url的链接会将我重定向至我是否未登录.该方法有效,但我认为这不是正确的方法,而且一旦登录,无法注销或切换帐户;似乎一旦登录,您将永远登录
  • 使用 https://developers.google.com/apps-script/reference/script/authorization-info#getAuthorizationUrl()获取身份验证网址-但我不知道如何使用返回的网址(将用户导航到Web应用程序框架顶部框架上的该页面均导致空白页面)
  • a link to the url google redirects me to if I am not logged on if the web app require the user to be logged in. That works, but I feel it is not the right way and also, once logged in, there is no way to logout or to switch account; it seems that once you are logged in, you are logged in forever
  • to use https://developers.google.com/apps-script/reference/script/authorization-info#getAuthorizationUrl() to get the auth url - but I don't know how to use the url it returns (navigating the user to that page in the web app frame on the top frame both result in a blank page)

如何获取登录(可能还包括交换机登录)URL,以允许匿名用户登录我的Web应用程序?

How can I get a login (and possibly a switch login) url to allow anonymous users to login in my web app?

推荐答案

为2个.gs Web应用程序项目创建了示例代码: 一个-无身份验证,作为所有者运行,匿名用户可以访问 两个-需要身份验证,以用户身份运行,任何人都可以访问

Created sample code for 2 .gs web app projects: one - no auth, runs as owner, anonymous can access two - needs auth, runs as user, anyone can access

...因为我不知道您的我能将用户重定向到URL"语句在代码中的样子.

...as I have no idea what your "I got it to work redirecting the user to the URL" statement looks like in code.

第一个文件具有一个带有单击侦听器的按钮,以充当登录按钮,但它只是要求进行window.top.location.href更改. 从客户端按钮单击被调用后,第二个应用正在使用ScriptApp.invalidateAuth();注销用户.

The 1st file has a button with a click listener to act as the login button, but it's just calling for a window.top.location.href change. The 2nd app is using ScriptApp.invalidateAuth(); to log users out after being called from a client-side button click.

演示-第一个网络应用程序网址

Demo - 1st web app url

我仍然会投票决定只提供第二个Web应用程序,但该链接会在新窗口中打开,并且正如我在评论中所指出的那样,上述设置会迫使用户每次注销后都重新授权.

I'd still vote to just offer a 2nd web app as a link that pops open in a new window though and as I note in the comment, the setup above forces users to re-authorize each time and after the signout.

这篇关于Google应用程序脚本网络应用程序,如何创建登录按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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