Skip to content

Commit

Permalink
feat: refactor based on sveltia-cms-auth (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
greatislander authored Jun 25, 2024
1 parent eee8da8 commit bcc0fbd
Show file tree
Hide file tree
Showing 19 changed files with 5,081 additions and 2,088 deletions.
5 changes: 1 addition & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
NODE_ENV=production
ALLOWED_DOMAINS=example.com,*.example.com # Domain patterns for CMS installations using the IDRC CMS Authenticator
OAUTH_CLIENT_ID="" # GitHub or GitLab OAuth application client ID
OAUTH_CLIENT_SECRET="" # GitHub or GitLab OAuth application client secret
ORIGINS=example.com,*.example.com # Domain patterns for CMS installations using the IDRC CMS Authenticator
PORT=3000
REDIRECT_URL=https://auth.example.com/callback # A full URL to the /callback route of your deployed IDRC CMS Authenticator. This will also be configured as the callback URL in your GitHub or GitLab OAuth application.
3 changes: 3 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALLOWED_DOMAINS=example.com,*.example.com
OAUTH_CLIENT_ID=client-id
OAUTH_CLIENT_SECRET=client-secret
44 changes: 44 additions & 0 deletions .github/workflows/lint-format-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint, format and test

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint-format-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies and lint files
run: |
npm ci
npm run lint
npm run format
npm run test
- name: Save code coverage to artifact
uses: actions/upload-artifact@v4
with:
name: code-coverage
path: "coverage/clover.xml"
retention-days: 5
upload-coverage:
runs-on: ubuntu-latest
needs:
- lint-format-test
steps:
- name: Fetch code coverage artifact
uses: actions/download-artifact@v4
with:
name: code-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
24 changes: 0 additions & 24 deletions .github/workflows/lint.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.env
coverage
node_modules
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lint-staged
npx --no-install lint-staged
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.0.1"
".": "0.0.1"
}
19 changes: 2 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,12 @@ Based on [netlify-cms-github-oauth-provider](https://github.com/vencax/netlify-c
2. Configure environment variables for the application in a `.env` file:

```bash
AUTH_TARGET=_self
NODE_ENV=production
# Domain patterns for CMS installations using the IDRC CMS Authenticator
ALLOWED_DOMAINS=example.com,*.example.com
# GitHub or GitLab OAuth application client ID
OAUTH_CLIENT_ID=""
# GitHub or GitLab OAuth application client secret
OAUTH_CLIENT_SECRET=""
# Domain patterns for CMS installations using the IDRC CMS Authenticator
ORIGINS=example.com,*.example.com
PORT=3000
# A full URL to the /callback route of your deployed IDRC CMS Authenticator.
# This will also be configured as the authorization callback URL in your GitHub or GitLab OAuth application.
REDIRECT_URL=https://auth.example.com/callback
```

GitLab requires additional information as follows:

```bash
OAUTH_PROVIDER=gitlab
SCOPES=api
OAUTH_AUTHORIZE_PATH=/oauth/authorize
OAUTH_TOKEN_PATH=/oauth/token
```

## Serving locally
Expand Down
12 changes: 7 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require("dotenv").config({ silent: true });

const express = require("express");
const cookieParser = require("cookie-parser");
const middleware = require("./middleware/index.js");
const port = process.env.PORT || 3000;

const app = express();
app.use(cookieParser());

app.get("/", (_req, res) => {
res.status(404).send();
});

app.get("/auth", middleware.auth);
app.get("/callback", middleware.callback);
app.get("/success", middleware.success);
app.get("/", middleware.index);

app.listen(port, () => {
console.log(`IDRC CMS Authenticator listening on port ${port}.`);
});
app.listen(port);
3 changes: 3 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"organizeImports": {
"enabled": true
},
"files": {
"ignore": ["coverage/"]
},
"linter": {
"enabled": true,
"rules": {
Expand Down
14 changes: 0 additions & 14 deletions middleware/auth.js

This file was deleted.

41 changes: 0 additions & 41 deletions middleware/callback.js

This file was deleted.

Loading

0 comments on commit bcc0fbd

Please sign in to comment.