0

I am trying to authenticate and get the events from my outlook calendar. Am able to login and authenticate the user but when I am trying to get the events, am getting cross origin issues.

Here's my code snippet:

<button id="SignIn" onclick="signIn()">Sign In</button>
 <h4 id="WelcomeMessage"></h4>
  
<script src="https://secure.aadcdn.microsoftonline-p.com/lib/1.0.12/js/adal.min.js"></script>
<script>
  var ADAL = new AuthenticationContext({
      instance: 'https://login.microsoftonline.com/',
      tenant: 'common', //COMMON OR YOUR TENANT ID

      clientId: '<its my client id>', //This is your client ID
      redirectUri: 'http://localhost:8000', //This is your redirect URI

      callback: userSignedIn,
      popUp: true
  });

 window.authContext = new AuthenticationContext(ADAL);

    var isCallback = authContext.isCallback(window.location.hash);
    authContext.handleWindowCallback();
  
  function signIn() {
      ADAL.login();
  }

  function userSignedIn(err, token) {
      console.log('userSignedIn called');
      if (!err) {
          console.log("token: " + token);
          showWelcomeMessage();
      }
      else {
          console.error("error: " + err);
      }
  }

  function showWelcomeMessage() {
      var user = ADAL.getCachedUser();
      var divWelcome = document.getElementById('WelcomeMessage');
      divWelcome.innerHTML = "Welcome " + user.profile.name;
   loadEvents();
  }

  function loadEvents() {
  console.log("in load events");
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "https://outlook.office.com/api/v2.0/me/calendarview?startDateTime=2016-10-01T01:00:00&endDateTime=2016-10-31T23:00:00&$select=Subject", true);
  xhr.send();}
</script>

At the end after running the script this is my error.

this is my error

Any help is appreciated . Thanks

Niranth Reddy
  • 493
  • 1
  • 11
  • 27
  • Is there a reason why you are using https://outlook.office.com instead of https://outlook.office365.com ? – AidaNow Apr 24 '17 at 18:27

1 Answers1

0

Here is a possibility: Your token is valid for outlook.office365.com but now you are trying to use outlook.office.com. To check if this is your case, check localStorage or sessionStorage. Please see the following image: enter image description here

AidaNow
  • 598
  • 5
  • 12