gmail 卡服务中的密码类型字段 [英] Password type field in gmail card service

查看:10
本文介绍了gmail 卡服务中的密码类型字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,在 gmail appscript 中,我们没有任何选项可以添加密码类型字段.

Right now, in gmail appscript we don't have any option to add a password type field.

Gmail Card Service for add-on 能够很好地显示其中的任何内容.我们可以与任何具有基本 REST api 的应用程序集成.我们需要对通常需要密码类型字段的内容进行身份验证.

Gmail Card Service for add-on has a very good ability to show any thing in it. We can integrate with any app which has basic REST api. We need authentication for that which commonly need password type field.

有什么办法可以显示密码类型字段吗?

Any work around to show password type field?

推荐答案

目前,Gmail 插件中不支持密码字段.

As of now, there is no support for password field in Gmail add-on.

但我们可以为它构建一个 hack.我希望只有在注册表中才需要密码.因此,我们可以使用 HTML 构建一个注册表单,并且可以通过授权操作来提供.

But we can build a hack for it. I hope password is needed only in registration forms. So, we can build a registration form using HTML and that can be served through authorization action.

CardService.newAuthorizationAction().setAuthorizationUrl(loginUrl)

在这里,在 Web 服务器中托管注册 HTML,并在上述代码段中将此 URL 作为loginUrl"传递.我们必须为注册/注册按钮提供 AuthorizationAction.因此,当用户单击此按钮时,会启动一个新的弹出页面,用户将提供用户名、密码等......在提交时,我们可以对所有表单数据进行编码并将其传递给父级 Gmail 插件将其重定向到可以生成附加组件的脚本重定向 URL.一旦重定向到脚本 URL,我们的附加代码中就会有一个回调,您可以从那里获取从注册 HTML 页面编码的表单字段.

Here, host registration HTML in a web server and pass this URL as "loginUrl" in the above snippet. We have to supply AuthorizationAction for the signup/register button. So, when the user clicks on this button, a new popup page is launched, the user will give the username, password, etc... onsubmit, we can encode all the form data and pass it to the parent Gmail add-on by redirecting it to a script redirection URL which you can generate an add-on. Once the redirection to the script URL comes, there will be a callback in our add-on code from there you can get the form fields which were encoded from registration HTML page.

function generateNewStateToken(callbackName, payload) {
        return ScriptApp.newStateToken()
        .withMethod(callbackName)
        .withArgument("payload", JSON.stringify(payload))
        .withTimeout(3600)
        .createToken();
    }

function getRedirectURI() {
    return "https://script.google.com/macros/d/" + ScriptApp.getScriptId() + "/usercallback";
  }

var state = generateNewStateToken("registerCallback", {"signup": true});
var reg_url = <reg_url> + "?redirect_uri=" + getRedirectURI() + "&state=" + state;

function registerCallback(cbResp) {
 // to access payload which passed in state token: cbResp.parameter.payload;

// in the html serialize all the form fields or data which you want to pass to plugin as query params like: <redirect_uri>?form_data=<encoded_data>&state=<state>

//Note: here the registration HTML page should parse the URL to get the state & redirect_uri from URL.

// to access form_data: cbResp.parameter.form_data

}

我希望这会对你有所帮助.这就是我们现在执行注册/登录流程的方式.

I hope this will help you. This is how we are doing the signup/signin flow now.

这篇关于gmail 卡服务中的密码类型字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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