Search code examples
javascriptmicrosoft-graph-apihello.js

How to combine two `hello.init` into one?


I am trying to use hello.js init API to sign in Microsoft Graph later. The code below is how I am doing now and it works.

repo

However, is there a way to combine these two hello.init into one? Thanks

hello.init({
  msft: {
    oauth: {
      version: 2,
      auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
    },
    scope_delim: ' ',
    form: false
  }
});

hello.init({
  msft: myAppId
}, {
  redirect_uri: window.location.href
});

Solution

  • I got the answer from the creator of hello.js Andrew Dodson on GitHub.

    hello.init ({msft:appid}) is short for hello.init ({msft:{id:appid}}) so you just need to define an id prop on your definition and it'll all work. Fyi this is undocumented and may change in the future.

    So in my case, the solution is

      hello.init({
          msft: {
            id: myAppId,
            oauth: {
              version: 2,
              auth: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
            },
            scope_delim: ' ',
            form: false
          },
        },
        { redirect_uri: window.location.href }
      );