Back

Does appwrite sent the correct Access-Control headers when authed with API key?

  • 1
  • Users
  • Accounts
  • Web
  • Self Hosted
Abdulramon Jemil
26 Jun, 2023, 04:24

I'm trying to use external Auth with appwrite by proxying client side requests with custom API endpoints that verify tokens and the make the request on behalf of the client with API keys as explained here https://discord.com/channels/564160730845151244/1121753945593872455/1122409631034122270

I'm worried about something though. While I can read permission on resources before sending them to the client or returning 401 Unauthorized error, appwrite provides no way to read app info from the server even when authed with API key. I want to know if I can still rely on appwrite to send the correct Access-Control-Allow-Origin headers to be forwarded to the client/browser on this case. Or I should request that the users define the origins again (maybe with env variables) on the server and handle that myself.

Hope it's understandable.

TL;DR
The user wants to know if Appwrite sends the correct Access-Control-Allow-Origin header when authenticated with an API key. They are using a proxy to shield the client from direct access to the Appwrite API, and want to know if they need to specify the access control headers themselves or if Appwrite handles it. The response suggests that if the proxy is on a different domain than the Appwrite API, the user needs to protect the proxy as well. The user wants to maintain the CORS rules enforced by Appwrite and mentions that they need to ensure that the Origin header is set on the request object. They are also using external authentication with App
Abdulramon Jemil
26 Jun, 2023, 04:32

Btw, I do know I'll have to make sure the Origin header is set on the request object for this to work.

Abdulramon Jemil
26 Jun, 2023, 05:32

I'll like to maintain the CORS rules enforced by Appwrite

Meldiron
26 Jun, 2023, 08:20

Hey 👋 CORS protect a hostname (domain). If your proxy is on different domain than Appwrite API, you would need to protect your proxy as well.

If you simply proxy Appwrite's response headers and your proxy lives on another domain, browser will (should) complain about CORS.

Make sense?

Abdulramon Jemil
26 Jun, 2023, 09:35

I don't really get you

Abdulramon Jemil
26 Jun, 2023, 09:42

Does that mean that appwrite still sends appropriate Access-Control-Allow-Origin header when authed via API key?

Anyway, I think this is what I should be doing; Since the proxy is meant to shield the client from direct access to the Appwrite API, the access control headers returned by Appwrite should not determine the access control headers I'll send to the client. I have to specify what access control headers I want to send to the client since the proxy's URL is what the client requests, not the Appwrite API URL. Do you think that makes sense?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more