Giter Site home page Giter Site logo

sveltia / sveltia-cms-auth Goto Github PK

View Code? Open in Web Editor NEW
28.0 3.0 80.0 276 KB

Cloudflare Workers script that allows Sveltia CMS to authenticate with GitHub and GitLab.

License: MIT License

JavaScript 100.00%
cloudflare-workers github-authentication oauth2 oauth2-client sveltia-cms decap-cms netlify-cms

sveltia-cms-auth's Introduction

Sveltia CMS Authenticator

This simple Cloudflare Workers script allows Sveltia CMS (or Netlify/Decap CMS) to authenticate with GitHub or GitLab.

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.

How to use it

Step 1. Deploy this project to Cloudflare Workers

Click the button below to start deploying.

Deploy to Cloudflare Workers

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.

Step 2. Register the Worker as an OAuth app

GitHub

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.

GitLab

Register a new OAuth application on GitLab (details) with the following properties, including your Worker URL from Step 1:

  • Name: Sveltia CMS Authenticator (or whatever)
  • Redirect URI: <YOUR_WORKER_URL>/oauth/redirect
  • Confidential: Yes
  • Scopes: api only

Once registered, the app’s Application ID and Secret will be displayed. We’ll use them in Step 3 below.

Step 3. Configure the Worker

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

  • GITHUB_CLIENT_ID: Client ID from Step 2
  • GITHUB_CLIENT_SECRET: Client Secret from Step 2; click the Encrypt button to hide it
  • GITHUB_HOSTNAME: Required only if you’re using GitHub Enterprise Server. Default: github.com

GitLab

  • GITLAB_CLIENT_ID: Application ID from Step 2
  • GITLAB_CLIENT_SECRET: Secret from Step 2; click the Encrypt button to hide it
  • GITLAB_HOSTNAME: Required only if you’re using a self-hosted instance. Default: gitlab.com

Both GitHub and GitLab

  • ALLOWED_DOMAINS: (Optional) 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 match www.example.com, blog.example.com, docs.api.example.com, etc. (but not example.com)
    • To match a www-less naked domain and all the subdomains, use example.com, *.example.com

Save and deploy.

Step 4. Update your CMS configuration

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 # or gitlab
   repo: username/repo
   branch: main
+  base_url: <YOUR_WORKER_URL>

Commit the change. Once deployed, you can sign into Sveltia CMS remotely with GitHub!

Acknowledgements

This project was inspired by netlify-cms-oauth-firebase.

sveltia-cms-auth's People

Contributors

au2001 avatar frankbits avatar kyoshino avatar nosovk avatar srtee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

sveltia-cms-auth's Issues

Failed to Deploy

While trying to deply, I am getting this error:

deploy
Unable to locate executable file: pnpm. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

It has issues with "Enable GitHub Actions".

Sorry, I don't have the required technical skills to understand or address the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.