This simple Cloudflare Workers script allows Sveltia CMS (or Netlify/Decap CMS) to authenticate with GitHub.
You don’t have to use it if you previously had Netlify/Decap CMS and your site is still being deployed to Netlify or if you have already used another 3rd party OAuth client.
You can use it if your site is hosted (or has been moved to) somewhere else, such as Cloudflare Pages or GitHub Pages, and you don’t have any other 3rd party client yet.
Click the button below to start deploying.
Alternatively, you can clone the project and run wrangler deploy
locally.
Once deployed, open your Cloudflare Workers dashboard, select the sveltia-cms-auth
service, then the worker URL (https://sveltia-cms-auth.<SUBDOMAIN>.workers.dev
) will be displayed. Copy it for Step 2. It will also be used in Step 4.
Register a new OAuth application on GitHub (details) with the following properties, including your Worker URL from Step 1:
- Application name:
Sveltia CMS Authenticator
(or whatever) - Homepage URL:
https://github.com/sveltia/sveltia-cms-auth
(or whatever) - Application description: (can be left empty)
- Authorization callback URL:
<YOUR_WORKER_URL>/callback
Once registered, click on the Generate a new client secret button. The app’s Client ID and Client Secret will be displayed. We’ll use them in Step 3 below.
Go back to the sveltia-cms-auth
service page on Cloudflare, select Settings > Variables, and add the following Environment Variables to your worker (details):
GITHUB_CLIENT_ID
: Client ID from Step 2GITHUB_CLIENT_SECRET
: Client Secret from Step 2; click the Encrypt button to hide itALLOWED_DOMAINS
: Your site’s hostname, e.g.www.example.com
- Multiple hostnames can be defined as a comma-separated list, e.g.
www.example.com, www.example.org
- A wildcard (
*
) can be used to match any subdomain, e.g.*.example.com
that will matchwww.example.com
,blog.example.com
,docs.api.example.com
, etc. (but notexample.com
) - To match a
www
-less naked domain and all the subdomains, useexample.com, *.example.com
- Multiple hostnames can be defined as a comma-separated list, e.g.
Save and deploy.
Open admin/config.yml
locally or remotely, and add your Worker URL from Step 1 as the new base_url
property under backend
:
backend:
name: github
repo: username/repo
branch: main
+ base_url: <YOUR_WORKER_URL>
Commit the change. Once deployed, you can sign into Sveltia CMS remotely with GitHub!
This project was inspired by netlify-cms-oauth-firebase
.