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
http api angular outlook typescript


source to share


No one has answered this question yet

Check out similar questions:

953
Access-Control-Allow-Origin Multiple Domains of Origin?
576
Is entity object allowed for HTTP DELETE request?
492
REST API error returns good practices
6
Angular2 - Can't get Set-Cookie from auth. answer (jaas, wf)
4
Sage One API - unsupported_grant_type
2
Access-Control-Allow-Origin header field not allowed by Access-Control-Allow-Headers in preflight response
0
Get a view access token
0
Instagram API not working through Nodejs
0
Passport password token updates



All Articles
Loading...
X
Show
Funny
Dev
Pics