6

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

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?

4

2 回答 2

5

截至目前,Gmail 插件中不支持密码字段。

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

CardService.newAuthorizationAction().setAuthorizationUrl(loginUrl)

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

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

}

我希望这能帮到您。这就是我们现在进行注册/登录流程的方式。

于 2018-02-27T13:47:03.923 回答
1

看起来您正在授权非 google 服务。请参阅 授权自定义 google 服务

于 2018-05-23T03:03:38.737 回答