-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #151 from AmazeeLabs/lagoon-SLB-204
SLB-204: token-based decap authentication
- Loading branch information
Showing
56 changed files
with
4,632 additions
and
2,241 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
<!DOCTYPE html> | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Decap</title> | ||
<script type="text/javascript" src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script> | ||
</head> | ||
<body> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
[dev] | ||
autoLaunch = false | ||
|
||
[functions] | ||
directory = "netlify/functions" | ||
|
||
[build] | ||
edge_functions = "netlify/edge-functions" | ||
|
||
[functions.strangler] | ||
included_files = ["public/404.html"] | ||
|
||
[[edge_functions]] | ||
path = "/" | ||
function = "homepage-redirect" | ||
function = "homepage-redirect" | ||
|
||
[[edge_functions]] | ||
path = "/admin/_github/*" | ||
function = "github-proxy-auth" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Context } from '@netlify/edge-functions'; | ||
|
||
// For some reason pnpm package imports break in edge handlers. | ||
import { | ||
JwtEncoder, | ||
PostmarkEmailBackend, | ||
TokenAuthHandler, | ||
} from '../../node_modules/@amazeelabs/token-auth-middleware/build/index.js'; | ||
|
||
export default async (request: Request, context: Context) => { | ||
if ( | ||
!(Netlify.env.has('JWT_SECRET') && Netlify.env.has('POSTMARK_API_TOKEN')) | ||
) { | ||
throw new Error( | ||
'Missing environment variables JWT_SECRET and POSTMARK_API_TOKEN.', | ||
); | ||
} | ||
|
||
const encoder = new JwtEncoder(Netlify.env.get('JWT_SECRET') as string); | ||
const backend = new PostmarkEmailBackend( | ||
{ | ||
// Grant access to everybody @amazeelabs.com. | ||
'*@amazeelabs.com': '*', | ||
}, | ||
'[email protected]', | ||
Netlify.env.get('POSTMARK_API_TOKEN') as string, | ||
'login-link', | ||
); | ||
|
||
const handler = new TokenAuthHandler('/admin/_github', encoder, backend, { | ||
tokenLifetime: 300, | ||
}); | ||
return handler.handle(request, context.next); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { Context } from '@netlify/functions'; | ||
import { githubProxy } from '@amazeelabs/decap-cms-backend-token-auth/proxy'; | ||
|
||
export default function (request: Request, context: Context) { | ||
if (!process.env.DECAP_GITHUB_TOKEN) { | ||
throw new Error('Missing environment variable DECAP_GITHUB_TOKEN.'); | ||
} | ||
return githubProxy(request, process.env.DECAP_GITHUB_TOKEN, '/admin/_github'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
extends: ['@amazeelabs/eslint-config'], | ||
root: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
** | ||
!build/* | ||
!CHANGELOG.md | ||
!README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@amazeelabs/prettier-config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Decap Token-Auth backend | ||
|
||
Decap backend that uses token authentication instead of Netlify Identity or | ||
similar services. This package is meant to be used in combination with the | ||
`@amazeelabs/token-auth-middleware` package. It contains a proxy service that | ||
can run as a serverless function and handle Decap requests with a dedicated | ||
Github token. | ||
|
||
## Usage | ||
|
||
For example, create a netlify edge function and simply pass the request to a | ||
proxy. | ||
|
||
```typescript | ||
import type { Context } from '@netlify/functions'; | ||
import { githubProxy } from '@amazeelabs/decap-cms-backend-token-auth/proxy'; | ||
|
||
export default function (request: Request, context: Context) { | ||
if (!process.env.DECAP_GITHUB_TOKEN) { | ||
throw new Error('No Github token configured'); | ||
} | ||
return githubProxy(request, process.env.DECAP_GITHUB_TOKEN, '/admin/_github'); | ||
} | ||
``` | ||
|
||
> [!IMPORTANT] | ||
> Make sure to configure `@amazeelabs/token-auth-middleware` to use the same | ||
> `/admin/_github` path and protect it properly. | ||
Then inject and configure the `TokenAuthBackend` in Decap CMS. | ||
|
||
```typescript | ||
import { TokenAuthBackend } from '@amazeelabs/decap-cms-backend-token-auth'; | ||
import CMS from 'decap-cms-app'; | ||
|
||
CMS.registerBackend('token-auth', TokenAuthBackend); | ||
|
||
CMS.init({ | ||
config: { | ||
backend: { | ||
name: 'token-auth', | ||
api_root: '/admin/_github', | ||
repo: 'myorg/myrepo', | ||
branch: 'main', | ||
}, | ||
}, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "@amazeelabs/decap-cms-backend-token-auth", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"type": "module", | ||
"exports": { | ||
"./proxy": { | ||
"import": "./build/proxy.js" | ||
}, | ||
"./backend": { | ||
"import": "./build/backend.js" | ||
} | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"proxy": [ | ||
"build/proxy.d.ts" | ||
], | ||
"backend": [ | ||
"build/backend.d.ts" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"test:static": "tsc --noEmit && eslint \"**/*.{ts,tsx,js,jsx}\" --ignore-path=\"./.gitignore\"", | ||
"test:unit": "vitest run --passWithNoTests", | ||
"prep": "rm -rf build && tsc -p tsconfig.build.json", | ||
"watch": "tsc --watch -p tsconfig.build.json" | ||
}, | ||
"dependencies": { | ||
"@amazeelabs/token-auth-middleware": "workspace:*", | ||
"@emotion/styled": "^11.11.0", | ||
"decap-cms-backend-github": "^3.1.0", | ||
"decap-cms-lib-util": "^3.0.2", | ||
"decap-cms-ui-default": "^3.1.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/semaphore": "^1.1.4", | ||
"@octokit/types": "^12.6.0", | ||
"@amazeelabs/eslint-config": "1.4.43", | ||
"@amazeelabs/prettier-config": "1.1.3", | ||
"@types/node": "18.19.17", | ||
"@types/react": "^18.2.60", | ||
"vitest": "^1.3.1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} |
Oops, something went wrong.