{"id":19745185,"url":"https://github.com/castle/castle-cloudflare-worker-sample","last_synced_at":"2025-04-30T07:33:57.920Z","repository":{"id":40234297,"uuid":"337696602","full_name":"castle/castle-cloudflare-worker-sample","owner":"castle","description":"Castle Cloudflare Worker Sample","archived":false,"fork":false,"pushed_at":"2022-05-19T15:10:55.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-03-25T23:10:02.524Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/castle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-10T11:00:30.000Z","updated_at":"2024-03-25T23:10:02.525Z","dependencies_parsed_at":"2022-09-11T22:01:49.398Z","dependency_job_id":null,"html_url":"https://github.com/castle/castle-cloudflare-worker-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-cloudflare-worker-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-cloudflare-worker-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-cloudflare-worker-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/castle%2Fcastle-cloudflare-worker-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/castle","download_url":"https://codeload.github.com/castle/castle-cloudflare-worker-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224202878,"owners_count":17272807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T02:04:51.070Z","updated_at":"2024-11-12T02:04:51.514Z","avatar_url":"https://github.com/castle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg align=\"center\" alt=\"Castle logo\" src='./assets/castle-logo.png' width='150'/\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eCastle Cloudflare Worker Sample\u003c/h1\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimage alt=\"Package version\" src=\"https://img.shields.io/github/package-json/v/castle/castle-cloudflare-worker-sample\"/\u003e\n  \u003cimage alt=\"License\" src=\"https://img.shields.io/github/license/castle/castle-cloudflare-worker-sample\"/\u003e\n\u003c/div\u003e\n\n## Overview\n\nThe Castle Cloudflare Worker allows you to put Castle's risk engine right on the edge, in a Cloudflare worker.\n\n## How it works\n\nOnce you've installed the worker and configured the `CASTLE_API_SECRET`, the worker will listen for POSTs to the `/users/sign_up` route.\n\nThe POST must include a Castle `request_token`, and optionally an `email` field that is used map events to existing users.\n\nWhen the worker receives the POST, it will in turn make a POST to Castle, and receive a risk score in return. If result has `deny` action, then the worker will respond with a defined response. Otherwise worker with simply forward the request to the upstream.\n\n## Prerequisites\n\nYou'll need a Castle account and a Cloudflare account to get started.\n\nAdditionally you need to [install the Castle.js script](https://docs.castle.io/docs/sdk-browser#configuration), which will be used to generate a unique \"request token\" for each request to your server. Without this request token, requests to Castle's API will be rejected.\n\n### Castle\n\nIf you don't have a Castle account already, you can [set up a free trial](https://dashboard.castle.io/signup/new). You will need your Castle API Secret, which can be found in the Settings section of your Castle dashboard.\n\n### Cloudflare\n\nIf you're going to use the `Deploy with Workers` option (see below), you'll need your Cloudflare account ID and an API Token.\n\n## Installation\n\nThere are two options for installing this worker, a \"manual\" method and a `Deploy with Workers` method.\n\n### Manual installation\n\n1. Create or open the Cloudflare worker where you would like to install the Castle worker code.\n\n2. Add Environment Variable to your worker:\n\n   - `CASTLE_API_SECRET` — assign your Castle API Key to this variable.\n\n   You can retrieve your `CASTLE_API_SECRET` from [the settings section of your Castle dashboard](https://dashboard.castle.io/settings/general).\n\n3. Copy and paste the contents of the `index.js` file in this repo to your Worker.\n\n4. Customize for your needs\n\n5. Preview/Save and deploy!\n\n### Installation using `Deploy with Workers`\n\nPress the `Deploy with Workers` button. You will be redirected to a dedicated deployment page.\n\n[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/castle/castle-cloudflare-worker-sample)\n\n### Detailed Installation steps\n\n1. Authorize GitHub with Workers\n\n   Authorization allows to fork the project from Github and deploy it after finishing the setup.\n\n2. Configure Cloudflare Account\n\n   Add Cloudflare Account ID (`CF_ACCOUNT_ID`) and Cloudflare API Token with \"Edit Workers\" permissions (`CF_API_TOKEN`). They will be auto-uploaded as Github actions secrets.\n\n   After this step, `castle-cloudflare-worker-sample` repository should be forked to your organization.\n\n3. Deploy with GitHub Actions\n\n   Navigate to `Settings \u003e Secrets` tab of the forked repository.\n\n   Update `Repository Secrets` — add Castle API secret available in [Castle Dashboard](https://dashboard.castle.io/settings/general) as `CASTLE_API_SECRET` to Github actions secrets.\n\n   Now you can finalize the deployment by pressing the `Deploy` button.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastle%2Fcastle-cloudflare-worker-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcastle%2Fcastle-cloudflare-worker-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcastle%2Fcastle-cloudflare-worker-sample/lists"}