Back

Validating Appwrite Auth tokens on Cloudflare Workers

  • 0
  • Self Hosted
  • Auth
  • Functions
Ramtin
25 Apr, 2024, 20:26

Hi! I'm interested in leveraging Cloudflare workers to run certain functions, but I also want to restrict access to these functions to only logged in users. These functions are entirely independent of any database connection and solely serve as REST APIs to fetch data from other APIs. Is it possible to validating appwrite Auth tokens on Cloudflare Workers to make the functions only available to logged in users?

TL;DR
Developers are having trouble validating Appwrite Auth tokens on Cloudflare Workers and working with Appwrite JWT secret key. The solution is to use 'jose' for verification, and there is a package available for Appwrite version 1.5.
D5
25 Apr, 2024, 20:40
D5
25 Apr, 2024, 20:48

You can't restrict completely the access to the workers, but once they're executed you can check if the user has or not a valid JWT and their permissions. Then make something based on that.

If you use Appwrite functions instead, you can restrict their execution to specific users or teams

Ramtin
26 Apr, 2024, 03:52

It seems that running the Appwrite Node.js server SDK on Cloudflare workers isn't feasible due to Cloudflare's limited support for Node.js APIs and we need to use 'jose' (github.com/panva/jose) for this purpose. However, it requires the JWT secret key to verify the signed JWT tokens. Any ideas on how to obtain the Appwrite JWT secret key?

Steven
26 Apr, 2024, 18:38

if you're on Appwrite version 1.5, you can use https://www.npmjs.com/package/node-appwrite/v/12.1.0-rc.4

Ramtin
26 Apr, 2024, 23:00

@Steven I was able to successfully install the version you sent on a worker, but I'm not sure how I can validate the received token using the Client instance (https://appwrite.io/docs/products/auth/jwt). Also, I was wondering if the validation will be done locally on the worker, or if it sends a request to my appwrite server every time I initiate a new client instance on worker? Thanks

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