Microsoft Graph API CORS Policy issue

Neha Sevlani 26 Reputation points
2022-12-28T06:15:48.66+00:00

I have build an Office Addin. I want to access mail, send mail using Microsoft Graph API .
Have registered App in Azure AD following link "https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code".

But, i am calling below API, i am getting CORS issue
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize?scope=Mail.Read&response_type=code&client_id=.....&redirect_uri=https://localhost:3000' from origin 'https://localhost:3000"

Error in console:
Access to XMLHttpRequest at 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?scope=Mail.Read&response_type=code&client_id=...&redirect_uri=https://localhost:3000' from origin 'https://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,406 Reputation points
    2022-12-28T08:46:13.707+00:00

    Hi @Neha Sevlani

    Is your app a single-page app (SPA)? The redirect URIs for SPAs that use the auth code flow requires special configuration.

    274535-image.png

    However, the SPA redirect type is backward-compatible with the implicit flow. Apps currently using the implicit flow to get tokens can move to the spa redirect URI type without issues and continue using the implicit flow. So if your application is a SPA, then using implicit flow is the best choice.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.