How to fix CORS Error on Custom Domains for Azure Web App

隆Y 0 Reputation points
2024-08-20T06:42:55.0433333+00:00

Hi everyone,

Im currently building a small web app (dockerized, frontend served statically + backend bundled together) that is only accessible by a specific group managed by Entra ID. This is done via the provided Authentication inside the App Service.
Thus far everything works fine.

Now i want to add a Custom Domain to my App Service.
I added these to its section and also added the A Record and TXT Record to the domain provider (Changes are already applied to all DNS). This also still works. When i enter the custom domain or the default domain i get redirected to the login mask and can only access the site when im authenticated.

Here comes my problem:
When sending a request from my custom domain to my backend i get a CORS Error.
However when i send it directly from my default domain i have no issues.

Now im not sure where the problem is coming from, since i didnt really change much except the custom domain. Ive set up the redirect urls in the app registration and the authentication section of the app service. The storage in my browser shows an AppServiceAuthSession Cookie. And i double checked the Authentification Process (when logging in with a user without the necessary group, i cannot access the website).

Whats different is the request i can see on the network tab. Somehow it doesnt contain the cookie..
Do i have to manually set the cookies when i use custom domains? Currently my function is super simple and looks like this..

async function search(query: string): Promise
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,663 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dan Rios 1,980 Reputation points MVP
    2024-08-20T13:30:20.04+00:00

    Have you added your custom domain to the App Service CORS? You can do this in the Portal (GUI) or via code.

    User's image

    Also this may be of use depending on how you want to implement this:

    https://video2.skills-academy.com/en-gb/azure/app-service/app-service-web-tutorial-rest-api#add-cors-functionality

    and also: https://video2.skills-academy.com/en-gb/azure/app-service/app-service-web-tutorial-rest-api#app-service-cors-vs-your-cors

    Let me know you get on. If this resolves your issue, please mark it as accepted so others can benefit.

    0 comments No comments

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.