Password type field in gmail card service

谁说胖子不能爱 提交于 2019-11-29 14:23:13
Sabbu

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

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)

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.

Looks like you are authorizing a non google service . Please refer to Authorizing custom google services .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!