/cloudflare-litgate-rust

Primary LanguageRustApache License 2.0Apache-2.0

Getting Started

A template for kick starting a Cloudflare worker that protects some URL by verifying a JWT generated by the Lit Protocol

Notes

This has only been tested to compile on Ubuntu 20.04 with emcc as the compiler. I could not get it to compile on a mac.

Usage

You will need Cloudflare Wrangler to build and deploy this. Install it using the instructions here: https://developers.cloudflare.com/workers/cli-wrangler/install-update

After installing it, run "wrangler login" to log in to your cloudflare account.

You also need to install EMCC for compilation using instructions here: https://emscripten.org/docs/getting_started/downloads.html

After installing it, make sure you expose emcc in your path by following the instructions that emcc gives after installation.

Before compiling, make sure you run export CC=emcc in your terminal to set emcc as the compiler.

Next, open at src/lib.rs. Every line that has a comment that starts with "LIT Developers" is something you should look at.

Specifically, you should set the protected_url variable on line 41 to the final URL you want to send your users to, if they authenticate successfully.

Building and Deploying on cloudflare

This template starts you off with a src/lib.rs file, acting as an entrypoint for requests hitting your Worker. Feel free to add more code in this file, or create Rust modules anywhere else for this project to use.

With wrangler, you can build, test, and deploy your Worker with the following commands:

# compiles your project to WebAssembly and will warn of any issues
wrangler build 

# run your Worker in an ideal development workflow (with a local server, file watcher & more)
wrangler dev

# deploy your Worker globally to the Cloudflare network (update your wrangler.toml file for configuration)
wrangler publish

Read the latest worker crate documentation here: https://docs.rs/worker