<@U04UQ68083H> Having a CORS error: Access to XMLH...
# ory-copilot
b
@chilly-king-10285 Having a CORS error: Access to XMLHttpRequest at 'https://auth-ory-dev.pudgyworld.com/self-service/registration?flow=28c9f165-6841-4927-9151-d98bc3e4d1e3' from origin 'https://auth-dev.pudgyworld.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
c
A message from kapa.ai
To solve Cross-Origin Resource Sharing (CORS) errors, you can use Ory Tunnel for local development. In production, you should add your domain to the Ory Project so that all requests from your frontend can be made to Ory under the same domain. Ory has a "deny by default" policy which means that the
Access-Control-Allow-Origin
header is only set on domains they own. You can configure custom domains to use specific CORS settings. For CORS to work properly, you should set the following values in your configuration:
Copy code
yaml serve:    admin:    cors:    enabled: true    allowed_origins:    - <https://example.com>    - https://*.<http://example.com|example.com>    allowed_methods:    - POST    - GET    - PUT    - PATCH    - DELETE    allowed_headers:    - Authorization    exposed_headers:    - Content-Type    public:    cors:    enabled: true    allowed_origins:    - <https://example.com>    - https://*.<http://example.com|example.com>    allowed_methods:    - POST    - GET    - PUT    - PATCH    - DELETE    allowed_headers:    - Authorization    exposed_headers:    - Content-Type
Remember to replace
<https://example.com>
and
https://*.<http://example.com|example.com>
with your own domain. If you're building Single-Page Apps (SPAs) and you want the application to access the Ory Identities Public API, you need to configure your AJAX request to include cookies, because AJAX doesn't send cookies by default. For example, when using the browser's
fetch
function, you need to set
credentials: 'include'
. For more information, you can refer to the following sources: - [Ory Documentation on CORS](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#cors-errors) - [Ory Documentation on Custom Domains](https://www.ory.sh/docs/guides/custom-domains) - [Ory Documentation on Troubleshooting CSRF](https://www.ory.sh/docs/troubleshooting/csrf#accessing-apis-from-client-side-javascript--ajax) - [Ory Documentation on Setting up CORS](https://www.ory.sh/docs/guides/cors) - [Mozilla Documentation on CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
b
@chilly-king-10285 We have a custom domain set up and everything works fine until /registration is hit.
c
A message from kapa.ai
If you're encountering issues when hitting the
/registration
endpoint, it could be due to a number of reasons. Here are a few things you can check: 1. CORS Configuration: Ensure that your CORS settings are correctly configured for your custom domain. Ory has a "deny by default" policy, which means that the
Access-Control-Allow-Origin
header is only set on domains they own. You need to add your custom domain to the Ory Project so that all requests from your frontend can be made to Ory under the same domain. 2. Domain Propagation: After adding the domain in the Ory Console, it can take up to 24 hours for your changes to propagate. Ory will continuously recheck its status to see if it was configured with your registrar. You can manually recheck on the custom domains page, or check the value to set with your DNS provider. 3. Active Status: When the domain is reachable, it will have the "Active status". The CORS status will show "Inactive" while the domain is pending verification. After the domain is verified, the CORS status will show "Enabled/Disabled". 4. AJAX Requests: If you're building Single-Page Apps (SPAs) and you want the application to access the Ory Identities Public API, you need to configure your AJAX request to include cookies, because AJAX doesn't send cookies by default. For example, when using the browser's
fetch
function, you need to set
credentials: 'include'
. For more detailed information, you can refer to the following sources: - [Ory Documentation on CORS](https://www.ory.sh/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#cors-errors) - [Ory Documentation on Custom Domains](https://www.ory.sh/docs/guides/custom-domains) - [Ory Documentation on Troubleshooting CSRF](https://www.ory.sh/docs/troubleshooting/csrf#accessing-apis-from-client-side-javascript--ajax) - [Ory Documentation on Setting up CORS](https://www.ory.sh/docs/guides/cors) - [Mozilla Documentation on CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)