1

I am attempting to authenticate a Excel Web Add-in(custom funcitons) with IdentityServer4 on .NET Core 2.2 using office-js-helpers in Visual Studio 2019

  1. Adding an endpoint for my own IdentityServer, im pretty sure i need to set a clientSecret? But i can find no information about this in endpointManager. https://github.com/OfficeDev/office-js-helpers/blob/master/src/authentication/endpoint.manager.ts

Messing around with custom endpoint unsuccessfully I decided to try the authors code using a preset endpoint. Supposed working demo located here: https://github.com/OfficeDev/office-js-helpers/tree/master/demo

  1. After c/p'ing the demo:
    • clicking microsoft login opens the auth dialog properly prompting for username + password,
    • it auths OK (access_token is displayed in browserurl) - but never reaches the callback then() in js so that i can get the token.

Has anyone gotten oauth2 to work properly from any office add in using office-js-helpers? (or any other library for that matter).

Any help is appreciated.

The main goal is to auth with the identityserver that i have set up. But right now i just need SOME working solution using the preset endpoints defined by the authors of office-js-helpers.

here is my code:

<!DOCTYPE html>
<html>
<head>
    <title>Office Helpers Demo</title>
    <link rel="stylesheet" href="https://unpkg.com/office-ui-fabric-js@1.4.0/dist/css/fabric.min.css" />
    <link rel="stylesheet" href="https://unpkg.com/office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css" />
    <script src="https://unpkg.com/jquery@3.2.1/dist/jquery.js"></script>
    <script src="https://unpkg.com/core-js@2.5.1/client/core.js"></script>
    <script src="https://unpkg.com/@microsoft/office-js-helpers@1.0.0/dist/office.helpers.min.js"></script>
</head>
<body>
    <button class="login" data-provider="Dropbox">Sign into Dropbox</button>
    <button class="login" data-provider="Microsoft">Sign into Microsoft</button>
    <pre id="output"></pre>
<script>
    (function ($) {

        function prettify(data) {
            let json = JSON.stringify(data);
            json = json.replace(/{/g, "{\n\n\t");
            json = json.replace(/,/g, ",\n\t");
            json = json.replace(/}/g, ",\n\n}");
            return json;
        }

        $("document").ready(function () {
            if (OfficeHelpers.Authenticator.isAuthDialog()) {
                return;
            }

            let output = $("#output");
            let authenticator = new OfficeHelpers.Authenticator();


            authenticator.endpoints.registerMicrosoftAuth("f59e8034-6e3c-4ba6-9fb5-1342d27d0123");
            authenticator.endpoints.registerDropboxAuth("tkvf431lh8d9hci");

            $(".login").click(function () {
                let provider = $(this).data("provider");
                output.text("Authenticating with " + provider + "...");

                authenticator.authenticate(provider, true)
                    .then(function (token) {
                        output.text(prettify(token));
                    })
                    .catch(function (error) {
                        output.text(prettify(error));
                    });
            });
        });
    })(jQuery);
</script>
</body>
</html>
niho
  • 11
  • 2
  • Realizing i don't necesarily need a clientSecret using implicit flow i now have the authentication working. Running the excel web app through visual studio and excel, the problem remains that after successfull auth, the then() callback is never reached. – niho Sep 13 '19 at 08:03
  • Having the same issue. Did you solve it? – Peter Nov 09 '20 at 13:22

0 Answers0