Login redirect loop when accessing via cdn

I am using Cloudfront CDN to speed up my nextcloud install as it is in a shared host. When I try to access from my CDN url (something like asdfasdghasda.cloudfront.net) I go back to the login screen even when I know that I am entering the correct username and password. The login from the original domain (mydomain.com/nextcloud) works fine, and I’ve tried with Azure CDN and it works too.

Any clues?

I’m not a CDN expert, but speaking of proxies, this can happen if you filter out the authentication headers.

I had all the headers forwarded from CDN configuration.