CORS outlook api: access not allowed

I can't count how many times I have anointed CORS. We are currently trying to access the Outlook API to send emails and stuff. We follow the tutorial, do everything in Postman, and it works. Now we want to implement it in our Angular 2 app with the following code:

requestAccessToken(code: string) 
{
  if (code) {
  var headers = new Headers();
  headers.append("Content-Type", 'application/x-www-form-urlencoded');
  var requestoptions = new RequestOptions({
    headers: headers,
    withCredentials: false // tried true too
  })
  let body = `grant_type=authorization_code&
            redirect_uri=http://localhost:4200&
            code=`+ code + `&
            client_id=4e...ab&
            client_secret=CE.....BC`

  this.http.post("https://login.microsoftonline.com/common/oauth2/v2.0/token", body, requestoptions).subscribe((data) =>
  {
    console.log("data: " + data);
  },
    error =>
    {
      console.log("error: " + error);
    });
  }
}

      

Our answer looks like this:

{
"token_type":"Bearer",
"scope":"calendars.read calendars.read.shared calendars.readwrite calendars.readwrite.shared contacts.read 
contacts.read.shared mail.read 
user.read",
"expires_in":3599,"ext_expires_in":0,
"access_token":"ey...NjQ",
"refresh_token":"OAQABAAA...Fd8JA"
}

      

That's for sure, but I want, but I can’t extract the token from it and the following is logged in my browser:

Google Chrome magazine

As you can see, the error is logged, not data, and Chrome is complaining about CORS. I am really stuck and the only thing the internet says is to change the server settings, which of course is not possible with the login.microsoftonline.com url

+3


source to share





All Articles