Skip to content
Open

w #60

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"workbench.colorCustomizations": {
"terminal.background": "#24283c",
"terminal.foreground": "#E5E9F0",
"terminalCursor.background": "#E5E9F0",
"terminalCursor.foreground": "#E5E9F0",
"terminal.ansiBlack": "#2E3440",
"terminal.ansiBlue": "#EBCB8B",
"terminal.ansiBrightBlack": "#4C566A",
"terminal.ansiBrightBlue": "#EBCB8B",
"terminal.ansiBrightCyan": "#D08770",
"terminal.ansiBrightGreen": "#BF616A",
"terminal.ansiBrightMagenta": "#A3BE8C",
"terminal.ansiBrightRed": "#88C0D0",
"terminal.ansiBrightWhite": "#8FBCBB",
"terminal.ansiBrightYellow": "#5E81AC",
"terminal.ansiCyan": "#D08770",
"terminal.ansiGreen": "#BF616A",
"terminal.ansiMagenta": "#A3BE8C",
"terminal.ansiRed": "#88C0D0",
"terminal.ansiWhite": "#E5E9F0",
"terminal.ansiYellow": "#5E81AC",
"activityBar.background": "#362C1A",
"titleBar.activeBackground": "#4C3E24",
"titleBar.activeForeground": "#FBFAF8"
}
}
3 changes: 2 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import icon from "astro-icon";

// https://astro.build/config
export default defineConfig({
site: "https://astros.zank.studio",
site: "https://www.deskcode.nl",
vite: {
define: {
__DATE__: `'${new Date().toISOString()}'`,
},
},

integrations: [
tailwind(),
sitemap(),
Expand Down
Binary file modified bun.lockb
100644 → 100755
Binary file not shown.
31 changes: 31 additions & 0 deletions functions/api/auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export async function onRequest(context) {
const {
request, // same as existing Worker API
env, // same as existing Worker API
params, // if filename includes [id] or [[path]]
waitUntil, // same as ctx.waitUntil in existing Worker API
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;

const client_id = env.GITHUB_CLIENT_ID;

try {
const url = new URL(request.url);
const redirectUrl = new URL('https://github.com/login/oauth/authorize');
redirectUrl.searchParams.set('client_id', client_id);
redirectUrl.searchParams.set('redirect_uri', url.origin + '/api/callback');
redirectUrl.searchParams.set('scope', 'repo user');
redirectUrl.searchParams.set(
'state',
crypto.getRandomValues(new Uint8Array(12)).join(''),
);
return Response.redirect(redirectUrl.href, 301);

} catch (error) {
console.error(error);
return new Response(error.message, {
status: 500,
});
}
}
78 changes: 78 additions & 0 deletions functions/api/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function renderBody(status, content) {
const html = `
<script>
const receiveMessage = (message) => {
window.opener.postMessage(
'authorization:github:${status}:${JSON.stringify(content)}',
message.origin
);
window.removeEventListener("message", receiveMessage, false);
}
window.addEventListener("message", receiveMessage, false);
window.opener.postMessage("authorizing:github", "*");
</script>
`;
const blob = new Blob([html]);
return blob;
}

export async function onRequest(context) {
const {
request, // same as existing Worker API
env, // same as existing Worker API
params, // if filename includes [id] or [[path]]
waitUntil, // same as ctx.waitUntil in existing Worker API
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;

const client_id = env.GITHUB_CLIENT_ID;
const client_secret = env.GITHUB_CLIENT_SECRET;

try {
const url = new URL(request.url);
const code = url.searchParams.get('code');
const response = await fetch(
'https://github.com/login/oauth/access_token',
{
method: 'POST',
headers: {
'content-type': 'application/json',
'user-agent': 'cloudflare-functions-github-oauth-login-demo',
'accept': 'application/json',
},
body: JSON.stringify({ client_id, client_secret, code }),
},
);
const result = await response.json();
if (result.error) {
return new Response(renderBody('error', result), {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
status: 401
});
}
const token = result.access_token;
const provider = 'github';
const responseBody = renderBody('success', {
token,
provider,
});
return new Response(responseBody, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
status: 200
});

} catch (error) {
console.error(error);
return new Response(error.message, {
headers: {
'content-type': 'text/html;charset=UTF-8',
},
status: 500,
});
}
}
12 changes: 12 additions & 0 deletions kvk/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
172 changes: 172 additions & 0 deletions kvk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars
.wrangler/
6 changes: 6 additions & 0 deletions kvk/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"useTabs": true
}
Loading