Note: This is a fork of the original decap-oauth project.
External OAuth provider for Decap CMS. The following environment variables must be set for it to work:
OAUTH_CLIENT_ID=(insert_the_client_id)
OAUTH_SECRET=(insert_the_secret)
OAUTH_ORIGINS=www.example.com,oauth.mysite.comWhen using GitHub Enterprise, please set OAUTH_HOSTNAME to the proper value.
Documentation available on docs.rs.
To use this provider, you need to create a new OAuth application on GitHub. Follow these steps:
-
Go to GitHub Developer Settings:
- Log in to your GitHub account.
- Click on your profile picture in the top-right corner and select Settings.
- In the left sidebar, click on Developer settings.
- Click on OAuth Apps, then click the New OAuth App button.
-
Fill in the Application Details:
- Application name: A descriptive name for your application (e.g., "Decap CMS Auth").
- Homepage URL: The URL of your website or Decap CMS instance.
- Authorization callback URL: This is the URL where users will be redirected after they authorize the application. It should be in the format
https://<your-oauth-provider-domain>/callback. For example, if you are running this service athttps://oauth.example.com, the callback URL will behttps://oauth.example.com/callback.
-
Generate Client ID and Secret:
- After creating the application, you will be redirected to its page.
- You will see your Client ID. Copy this value and set it as the
OAUTH_CLIENT_IDenvironment variable. - Click the Generate a new client secret button. Copy the generated secret and set it as the
OAUTH_SECRETenvironment variable. Note: This secret is only displayed once, so make sure to save it securely.
To run the application using Docker, first build the image:
docker build -t decap-cms-oauth .Then, run the container with the required environment variables. The container uses the PORT environment
variable (default 3005). Map it to a host port with -p as usual.
docker run \
-e OAUTH_CLIENT_ID=<your_client_id> \
-e OAUTH_SECRET=<your_secret> \
-e OAUTH_ORIGINS=<your_origins> \
-e PORT=3005 \
-e ADDRESS=127.0.0.1 \
-p 8080:3005 \
-v /etc/ssl/certs:/etc/ssl/certs:ro \
decap-cms-oauthThe application will be available at http://localhost:8080 (host port 8080 mapped to container's PORT).
Alternatively, you can pull the pre-built image from the GitHub Container Registry:
docker pull ghcr.io/blackb1rd/decap-cms-oauth:latestThen, run the container. You can override the container PORT if you wish.
docker run \
-e OAUTH_CLIENT_ID=<your_client_id> \
-e OAUTH_SECRET=<your_secret> \
-e OAUTH_ORIGINS=<your_origins> \
-e PORT=3005 \
-e ADDRESS=127.0.0.1 \
-p 8080:3005 \
-v /etc/ssl/certs:/etc/ssl/certs:ro \
ghcr.io/blackb1rd/decap-cms-oauth:latestIn a production environment, it is recommended to run the application behind a reverse proxy like Nginx. This allows you to handle SSL termination, caching, and other advanced features.
Here is a sample Nginx configuration for proxying requests to the application:
server {
listen 80;
server_name your_domain.com;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name your_domain.com;
# SSL certificate configuration
ssl_certificate /path/to/your/fullchain.pem;
ssl_certificate_key /path/to/your/privkey.pem;
location / {
# Proxy to the application container's PORT (default 3005). If you run the container
# on a different host or provide a full ADDRESS with port (ADDRESS=host:port), adjust
# proxy_pass accordingly. Example (default):
proxy_pass http://localhost:3005;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}This configuration listens for both HTTP and HTTPS traffic. HTTP traffic is redirected to HTTPS. The proxy_pass directive forwards requests to the application running on localhost:3005.
To use this provider with Decap CMS, you need to configure the backend in your config.yml file. Set base_url to the URL of your deployed provider and auth_endpoint to auth.
backend:
name: github
repo: your-org/your-repo
base_url: https://your-oauth-provider.com
auth_endpoint: auth