How to make Graph API calls from Angular http://localhost:4200 port?

Bhoomesh Joshi 1 Reputation point
2021-09-24T05:53:59.403+00:00

Hello Everyone,

I have created one project in Angular. I need to GET/POST data from the SharePoint list.

I have created Microsoft Graph API App to achieve the same.

When I tried to GET/POST data in SharePoint list using Postman. It is working correctly.

But when I integrate that code in Angular and run that project on localhost throws me the below error.

"Access to XMLHttpRequest at 'https://login.microsoftonline.com/{{directoryId}}/oauth2/v2.0/token' from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,126 Reputation points
    2021-09-27T02:38:31.593+00:00

    Hi @Bhoomesh Joshi ,

    You could integrate the Microsoft Authentication Library for Angular into the application to obtain the necessary OAuth access token to call the Microsoft Graph

    Please refer to this article to use Microsoft Graph in Angular app: https://learn.microsoft.com/en-us/graph/tutorials/angular?tutorial-step=3


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.