如何在 Microsoft Word 加载项中使用 Google 登录

How to login with Google in Microsoft Word Add-In

下面的link建议使用Google Auth Lib,但是提供的githublink没有引用任何javascript库:

据我所知,我无法使用 Code FLow,因为它需要重定向 URL。我应该如何从 Microsoft Word Add-In 中的 Google 获取 Access Token

要使用 GoogleFacebook 等登录,您可以使用 office-js-helpers:

使用 npm 安装它:

npm install --save @microsoft/office-js-helpers

并且在您的代码中,在 Office.initialize 内:

Office.initialize = function (reason) {
    //...
    // This to inform the Authenticator to automatically close the authentication dialog once the authentication is complete.
    if (OfficeHelpers.Authenticator.isAuthDialog()) return;

    // register Google endpoint using
    authenticator.endpoints.registerGoogleAuth('GOOGLE-CLIENT-ID');
    authenticator
         .authenticate(OfficeHelpers.DefaultEndpoints.Google)
         .then(function (token) { console.log('_GOOGLE_TOKEN: ', token); })
         .catch(OfficeHelpers.Utilities.log);
}

就是这样!