You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Helps you troubleshoot and resolve Cross-Origin Resource Sharing issues when using Microsoft Entra ID.
4
4
ms.service: entra-id
5
-
ms.date: 07/04/2025
5
+
ms.date: 07/07/2025
6
6
ms.reviewer: willfid, v-weizhu
7
7
ms.custom: sap:Developing or Registering apps with Microsoft identity platform
8
8
---
@@ -12,7 +12,7 @@ This article provides guidance on troubleshooting and resolving Cross-Origin Res
12
12
13
13
## Understanding CORS
14
14
15
-
[Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/docs/Web/HTTP/Guides/CORS) is an [HTTP](https://developer.mozilla.org/docs/Glossary/HTTP)-header-based mechanism that allows a server to specify [origins](https://developer.mozilla.org/docs/Glossary/Origin)(domains, schemes, ports) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check whether the server permits the actual request. During this preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.
15
+
[Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/docs/Web/HTTP/Guides/CORS) is an [HTTP](https://developer.mozilla.org/docs/Glossary/HTTP)-header-based mechanism that allows a server to specify [origins](https://developer.mozilla.org/docs/Glossary/Origin)(domains, schemes, ports) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in order to check whether the server permits the actual request. During this preflight, the browser sends headers that indicate the HTTP method and headers that are used in the actual request.
16
16
17
17
For detailed information about CORS headers, refer to [CORS headers](https://developer.mozilla.org/docs/Glossary/CORS).
18
18
@@ -41,7 +41,7 @@ While developing an application, you might encounter the following CORS-related
41
41
> [!NOTE]
42
42
>
43
43
> - These errors are generated by Microsoft Entra ID. Request URLs in these errors often begin with `https://login.microsoftonline.com` or `https://<your-domain>.b2clogin.com`. The latter typically points to an Azure Active Directory B2C scenario.
44
-
> - If the error doesn't originate from Microsoft Entra ID, it looks like "Access to XMLHttpRequest at `https://app.contoso.com`." This article doesn't provide guidance for resolving external CORS issues. In such cases, you need to configure CORS in that environment.
44
+
> - If the error doesn't originate from Microsoft Entra ID, it looks like "Access to XMLHttpRequest at `https://app.contoso.com`." This article doesn't provide guidance on resolving external CORS issues. In such cases, you need to configure CORS in that environment.
45
45
46
46
## Cause
47
47
@@ -91,15 +91,15 @@ You can notice that the request contains an `Origin` header, but no `Access-Cont
91
91
92
92
## General solution
93
93
94
-
Implement your application architecture to follow the OAuth2 and OIDC standards. This solution can ensure your front-end application acquires an access token and includes it in the `Authorization` header to the API you're making your `XMLHttpRequest` to. Here are some [single-page application samples](/entra/identity-platform/sample-v2-code?tabs=apptype).
94
+
Implement your application architecture to follow the OAuth2 and OIDC standards. This solution can ensure your front-end application acquires an access token and includes it in the `Authorization` header of the request when you make your `XMLHttpRequest` to the API. Here are some [single-page application samples](/entra/identity-platform/sample-v2-code?tabs=apptype).
95
95
96
96
## Scenario-based solutions
97
97
98
98
Here are the most common scenarios. Not every scenario is listed in this article as every environment and app architecture is different.
99
99
100
100
### Scenario 1: Web app and Web API using authentication cookies
101
101
102
-
If your web app or framework makes `XMLHttpRequest` calls to its API endpoint and use the Web Apps authentication cookies, examine the `XMLHttpRequest` request in the Fiddler capture. It might look like this:
102
+
If your web app or framework makes `XMLHttpRequest` calls to its API endpoint and uses the Web Apps authentication cookies, examine the `XMLHttpRequest` request in the Fiddler capture. It might look like this:
103
103
104
104
```http
105
105
GET https://app.domain.com/… HTTP/1.1
@@ -133,7 +133,7 @@ If you use ASP.NET or ASP.NET Core, configure Microsoft Entra ID to avoid using
@@ -170,11 +170,11 @@ To resolve the issue in this scenario, use one of the following methods:
170
170
171
171
#### Method 1: Send a valid token
172
172
173
-
If you're passing an access token to your API resource, ensure the token is valid. Check if the token is expired. If it is, request a new access token. If you're using Microsoft Authentication Library for JavaScript (MSAL.js), use `acquireTokenSilent` every time to acquire a new token before passing it to your API. Don't cache this token yourself. Always use `acquireTokenSilent` to get the cached token directly from MSAL.
173
+
If you pass an access token to your API resource, ensure the token is valid. Check if the token is expired. If it is, request a new access token. If you use Microsoft Authentication Library for JavaScript (MSAL.js), use `acquireTokenSilent` every time to acquire a new token before passing it to your API. Don't cache this token yourself. Always use `acquireTokenSilent` to get the cached token directly from MSAL.
174
174
175
175
For more information, see [Single-page application: Acquire a token to call an API](/entra/identity-platform/scenario-spa-acquire-token).
176
176
177
-
Here's is an example of how it looks when passing a token to an API: [Single-page application: Call a web API](/entra/identity-platform/scenario-spa-call-api)
177
+
Here's is an example of how it looks when passing a token to an API: [Single-page application: Call a web API](/entra/identity-platform/scenario-spa-call-api).
178
178
179
179
#### Method 2: Use JWT bearer authentication
180
180
@@ -218,7 +218,7 @@ Based on OAuth2 specs and Security best practices, don't use the following flows
218
218
- Resource Owner Password Credential (ROPC)
219
219
- Confidential Client flows, such as Client Credentials or On-behalf-of flows
220
220
221
-
All other flows won't be supported in Single Page Applications. Microsoft Entra ID and B2C won't add the CORS headers for the unsupported flows.
221
+
All other flows aren't supported in Single Page Applications. Microsoft Entra ID and B2C don't add the CORS headers for the unsupported flows.
222
222
223
223
### Scenario 6: Using Microsoft Entra Application Proxy
224
224
@@ -227,7 +227,7 @@ If your app uses Microsoft Entra Application Proxy, see [Understand complex appl
227
227
## References
228
228
229
229
- [Enable Cross-Origin Requests (CORS) in ASP.NET Core](/aspnet/core/security/cors)
230
-
- [Enabling Cross-Origin Requests in ASP.NET Web API 2](/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api)
230
+
- [Enable Cross-Origin Requests in ASP.NET Web API 2](/aspnet/web-api/overview/security/enabling-cross-origin-requests-in-web-api)
231
231
- [Azure App Service REST API tutorial](/azure/app-service/app-service-web-tutorial-rest-api)
232
232
- [Azure API Management CORS policy](/azure/api-management/cors-policy)
0 commit comments