Javascript Azure AD Auth Ember JS v3.15

Javascript Azure AD Auth Ember JS v3.15,javascript,azure,ember.js,azure-active-directory,Javascript,Azure,Ember.js,Azure Active Directory,一般来说,我是JS的noob,但我已经为工作准备了一个简单的应用程序,它使用Ember.JS嵌入了一个Tableau仪表板。我开始认为余烬是不对的,但我对其他任何东西都不熟悉 我有一个索引路由和一条发送给用户的短消息,还有一个使用Microsoft按钮登录的路由。我只想在商业用户单击按钮时使用Azure AD对其进行身份验证。返回URL将是嵌入的路由,而应用程序路由只有一些页眉和页脚信息 我试着把样本分开,但我什么也没有得到。我甚至不知道什么错误会有意义,因为我甚至不确定这是否可行 我已将其放在

一般来说,我是JS的noob,但我已经为工作准备了一个简单的应用程序,它使用Ember.JS嵌入了一个Tableau仪表板。我开始认为余烬是不对的,但我对其他任何东西都不熟悉

我有一个索引路由和一条发送给用户的短消息,还有一个使用Microsoft按钮登录的路由。我只想在商业用户单击按钮时使用Azure AD对其进行身份验证。返回URL将是嵌入的路由,而应用程序路由只有一些页眉和页脚信息

我试着把样本分开,但我什么也没有得到。我甚至不知道什么错误会有意义,因为我甚至不确定这是否可行

我已将其放在index.html文件中

<script type="text/javascript" src="https://alcdn.msauth.net/lib/1.2.1/js/msal.js" integrity="sha384-9TV1245fz+BaI+VvCjMYL0YDMElLBwNS84v3mY57pXNOt6xcUYch2QLImaTahcOP" crossorigin="anonymous"></script>
<script type="text/javascript">
    if(typeof Msal === 'undefined')document.write(unescape("%3Cscript src='https://alcdn.msftauth.net/lib/1.2.1/js/msal.js' type='text/javascript' integrity='sha384-9TV1245fz+BaI+VvCjMYL0YDMElLBwNS84v3mY57pXNOt6xcUYch2QLImaTahcOP' crossorigin='anonymous'%3E%3C/script%3E"));
</script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" class="pre"></script>

谢谢你看这篇文章,如果我没有提供足够的信息来解决这个问题,我很抱歉。Python和SQL很容易让人恼火,但是JS在我情绪低落的时候不会停止踢我!

请看这里:通常用ember做oauth通常意味着你想使用
Tori
。似乎已经有了一个。试着使用它。
<button onclick="signIn()" type="submit" id="ms-login" />
<button type="button" class="hide" onclick="callApi()">Call Web API</button>
<pre class="response"></pre>

<script class="pre">

  // The current application coordinates were pre-registered in a B2C tenant.
  var appConfig = {
    b2cScopes: [?],
    webApi: "?"
  };

</script>

<script>
  "use strict";

  // configuration to initialize msal
  const msalConfig = {
      auth: {
          clientId: "{Application (client) ID}", //This is your client ID
          authority: "?", //This is your tenant info
          validateAuthority: false
      },
      cache: {
          cacheLocation: "localStorage",
          storeAuthStateInCookie: true
      }
  };

  // instantiate MSAL
  const myMSALObj = new Msal.UserAgentApplication(msalConfig);

  // request to signin - returns an idToken
  const loginRequest = {
      scopes: appConfig.b2cScopes
  };

  // request to acquire a token for resource access
  const tokenRequest = {
      scopes: appConfig.b2cScopes
  };

  // signin and acquire a token silently with POPUP flow. Fall back in case of failure with silent acquisition to popup
  function signIn() {
      myMSALObj.loginPopup(loginRequest).then(function (loginResponse) {
          getToken(tokenRequest).then(updateUI);
      }).catch(function (error) {
          logMessage(error);
      });
  }

  //acquire a token silently
  function getToken(tokenRequest) {
      return myMSALObj.acquireTokenSilent(tokenRequest).catch(function(error) {
        console.log("aquire token popup");
        // fallback to interaction when silent call fails
        return myMSALObj.acquireTokenPopup(tokenRequest).then(function (tokenResponse) {
        }).catch(function(error){
          logMessage("Failed token acquisition", error);
      });
    });
  }

  // updates the UI post login/token acqusition
  function updateUI() {
    const userName = myMSALObj.getAccount().name;
    console.log(myMSALObj.getAccount());
    logMessage("User '" + userName + "' logged-in");

    // add the logout button
    const authButton = document.getElementById('auth');
    authButton.innerHTML = 'logout';
    authButton.setAttribute('onclick', 'logout();');

    // greet the user - specifying login
    const label = document.getElementById('label');
    label.innerText = "Hello " + userName;

    // add the callWebApi button
    const callWebApiButton = document.getElementById('callApiButton');
    callWebApiButton.setAttribute('class', 'visible');
  }

  // calls the resource API with the token
  function callApi() {
    getToken(tokenRequest).then(function(tokenResponse) {
      callApiWithAccessToken(tokenResponse.accessToken);
    });
  }

  // helper function to access the resource with the token
  function callApiWithAccessToken(accessToken) {
    // Call the Web API with the AccessToken
    $.ajax({
      type: "GET",
      url: appConfig.webApi,
      headers: {
        'Authorization': 'Bearer ' + accessToken,
      },
    }).done(function (data) {
      logMessage("Web APi returned:\n" + JSON.stringify(data));
    })
      .fail(function (jqXHR, textStatus) {
        logMessage("Error calling the Web api:\n" + textStatus);
      })
  }

  // signout the user
  function logout() {
    // Removes all sessions, need to call AAD endpoint to do full logout
    myMSALObj.logout();
  }

  // debug helper
  function logMessage(s) {
    document.body.querySelector('.response').appendChild(document.createTextNode('\n' + s));
  }

</script>
<script class="pre">

  // The current application coordinates were pre-registered in a B2C tenant.
  var appConfig = {
    b2cScopes: [?],
    webApi: "?"
  };

</script>
const msalConfig = {
    auth: {
        clientId: "{Application (client) ID}", //This is your client ID
        authority: "?", //This is your tenant info
        validateAuthority: false
    },
    cache: {
        cacheLocation: "localStorage",
        storeAuthStateInCookie: true
    }
};