logo

Configuring CORS with Your Keycloak OIDC Client

Setting up Cross-Origin Resource Sharing (CORS) in Keycloak is vital when you’re integrating your OIDC client across domains. Misconfigured CORS can cause issues where requests from your frontend fail due to browser security restrictions.

Here’s a step-by-step guide. I’ve left placeholders for where you can insert screenshots to make this even clearer.

Step 1: Log in to the Keycloak Admin Console

1. Navigate to your Keycloak Admin Console. Typically, this is at http://<your-keycloak-url>:8080/admin.

2. Log in using your admin credentials.

Admin console login page

Step 2: Navigate to Your Client Configuration

1. In the admin console, select the realm where your client is configured.

2. Go to the Clients section in the left-hand menu.

3. Click on the client you want to configure. (we are assuming you already have an OIDC client ready. You can follow the PKCE client creation. It is an equivalent)

Client list

Step 3: Enable CORS for Your Client

1. In the client settings, locate the “Access Settings” tab.

2. Look for the “Web Origins” field:

• By default, this might be set to * (allow all origins) or in other versions, it might be set to nothing or +. Avoid * at all cost.

Web origins CORS

3. Specify the allowed origins (e.g., https://my-frontend-domain.com). If you have multiple origins, add each one separated by a newline. Using +, will enforce Keycloak’s hostname.

image
What the default settings may look like
Add your secured origins

Step 4: Test Your Configuration

1. Deploy your frontend and make a request to the Keycloak-protected backend.

2. Open the browser’s developer console:

• Navigate to the Network tab.

• Check the response headers to ensure Access-Control-Allow-Origin matches your frontend’s domain.

You can also use cURL to verify if the proper headers are returned by using the host parameter (-H).

Step 5: Debugging Tips

Check Keycloak Logs: If requests are being blocked, Keycloak logs often show the reason.

Browser Console Errors: Look for specific CORS-related error messages.

Server Configuration: Ensure your backend is not overriding CORS headers.

© 2025 All Rights Reserved. Made by Yasser