Как войти в систему с помощью Google надстройки Microsoft Word

В ссылке ниже предлагается использовать Google Auth Lib, но github предоставленная ссылка не относится к какой-либо библиотеке JavaScript:

Насколько я знаю, я не могу использовать Code FLow как это нужно URL перенаправления. Как я должен получить Access Token от Google в Microsoft Word Add-In?

1 ответ

Решение

Для того, чтобы войти используя Google, Facebookи т. д. вы можете использовать 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);
}

Это оно!

Другие вопросы по тегам