GithubHelp home page GithubHelp logo

abdonrd / appsscript-signaturesmanager Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 1.0 176 KB

A library that provides the ability to manage the signatures of Google Apps users in Google Apps Script.

JavaScript 100.00%

appsscript-signaturesmanager's Introduction

SignaturesManager for Google Apps Script

SignaturesManager for Google Apps Script is a library that provides the ability to manage the signatures of Google Apps users in Google Apps Script.

Setup

This library is already published as an Gooogle Apps Script, making it easy to include in your project. To add it to your script, do the following in the Google Apps Script code editor:

  1. Click on the menu item "Resources > Libraries..."
  2. In the "Find a Library" text box, enter the project key "MPv0nOH4iExMfjWuC7yAamfMyxiDDL4nZ" and click the "Select" button.
  3. Choose a version in the dropdown box (usually best to pick the latest version).
  4. Click the "Save" button.

Usage

For use this library is necessary to use the OAuth2 for Apps Script library.

1. Create the OAuth2 service

Example:

function getSignaturesService() {
    return OAuth2.createService('signatures')
        .setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
        .setTokenUrl('https://accounts.google.com/o/oauth2/token')

        .setClientId('...')
        .setClientSecret('...')

        .setCallbackFunction('authCallback')

        .setPropertyStore(PropertiesService.getUserProperties())

        .setScope('https://apps-apis.google.com/a/feeds/emailsettings/2.0/')

        .setParam('login_hint', Session.getActiveUser().getEmail())
        .setParam('access_type', 'offline');
}

2. Direct the user to the authorization URL

Example:

function showAuthorization() {
    var signaturesService = getSignaturesService();

    if (!signaturesService.hasAccess()) {
        var authorizationUrl = signaturesService.getAuthorizationUrl();,
            template = HtmlService.createTemplate(
            '<a href="<?= authorizationUrl ?>" target="_blank">Authorize</a>. ' +
            'Refresh the page when the authorization is complete.');

        template.authorizationUrl = authorizationUrl;

        return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);
    } else {
        ...
    }
}

3. Handle the callback

Example:

function authCallback(request) {
    var signaturesService = getSignaturesService(),
        isAuthorized = signaturesService.handleCallback(request);

    if (isAuthorized) {
        return HtmlService.createHtmlOutput('Success! You can close this tab.');
    }

    return HtmlService.createHtmlOutput('Denied. You can close this tab.');
}

4. Make the request

Example:

var signaturesService = getSignaturesService(),
    sm = SignaturesManager.create(signaturesService);

var currentSignature = sm.getSignatureByEmail('[email protected]');

sm.setSignatureByEmail('[email protected]', 'This will be my new signature!');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.