-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: live admin page authenticates with github #87
base: main
Are you sure you want to change the base?
Changes from all commits
940a8b5
e3f4574
43f81e2
77ca364
aaf2feb
ef8e69b
ae18038
cc272aa
ed18095
7c1acbe
8aca097
9dfcf36
24c2881
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"dependencies": { | ||
"@astrojs/check": "^0.5.3", | ||
"@astrojs/mdx": "^2.1.1", | ||
"@astrojs/node": "^8.3.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What did you need node for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Astro requires an ssr adapter in order to enable server side rendering : https://docs.astro.build/en/guides/server-side-rendering |
||
"@astrojs/react": "^3.1.0", | ||
"@astrojs/rss": "^4.0.5", | ||
"@astrojs/sitemap": "^3.0.5", | ||
|
@@ -25,8 +26,6 @@ | |
"@radix-ui/react-hover-card": "^1.0.7", | ||
"@radix-ui/react-icons": "^1.3.0", | ||
"@radix-ui/react-switch": "^1.1.0", | ||
"@staticcms/core": "^4.1.2", | ||
"@staticcms/proxy-server": "^4.0.4", | ||
"@types/react": "^18.2.64", | ||
"@types/react-dom": "^18.2.21", | ||
"astro": "^4.3.6", | ||
|
@@ -36,11 +35,13 @@ | |
"react-dom": "^18.2.0", | ||
"react-hook-form": "^7.51.3", | ||
"react-select": "^5.8.0", | ||
"simple-oauth2": "2.5.2", | ||
"tailwindcss": "^3.4.1", | ||
"typescript": "^5.3.3" | ||
}, | ||
"devDependencies": { | ||
"@brown-ccv/eslint-config": "^0.3.0", | ||
"@types/simple-oauth2": "^2.5.2", | ||
"eslint": "^8.56.0", | ||
"eslint-plugin-astro": "^0.31.4", | ||
"prettier": "^3.2.5", | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<meta name="robots" content="noindex" /> | ||
<link href="/admin/config.yml" type="text/yaml" rel="cms-config-url" /> | ||
<title>Content Manager</title> | ||
</head> | ||
<body> | ||
<!-- Dashboard script--> | ||
<script src="https://unpkg.com/decap-cms@^3.1.0-beta.2/dist/decap-cms.js"></script> | ||
<!-- CSS in preview panel --> | ||
<script> | ||
// @ts-expect-error CMS is defined globally | ||
// eslint-disable-next-line | ||
CMS.registerPreviewStyle("/global.css") | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const clientId = process.env.OAUTH_GITHUB_CLIENT_ID || import.meta.env.OAUTH_GITHUB_CLIENT_ID | ||
export const clientSecret = | ||
process.env.OAUTH_GITHUB_CLIENT_SECRET || import.meta.env.OAUTH_GITHUB_CLIENT_SECRET | ||
|
||
export const authUrl = `https://github.com/login/oauth/authorize?client_id=${clientId}&scope=repo,user` | ||
export const tokenUrl = "https://github.com/login/oauth/access_token" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export const prerender = "false" | ||
import type { APIRoute } from "astro" | ||
import { clientId, clientSecret, tokenUrl } from "./_config" | ||
|
||
export const GET: APIRoute = async ({ url, redirect }) => { | ||
const data = { | ||
code: url.searchParams.get("code"), | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
} | ||
|
||
let script | ||
|
||
try { | ||
const response = await fetch(tokenUrl, { | ||
method: "POST", | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify(data), | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const body = await response.json() | ||
|
||
const content = { | ||
token: body.access_token, | ||
provider: "github", | ||
} | ||
|
||
// This is what talks to the DecapCMS page. | ||
// Using window.postMessage we give it the token details in a format it's expecting | ||
script = ` | ||
<script> | ||
const receiveMessage = (message) => { | ||
window.opener.postMessage( | ||
'authorization:${content.provider}:success:${JSON.stringify(content)}', | ||
message.origin | ||
); | ||
|
||
window.removeEventListener("message", receiveMessage, false); | ||
} | ||
window.addEventListener("message", receiveMessage, false); | ||
|
||
window.opener.postMessage("authorizing:${content.provider}", "*"); | ||
</script> | ||
` | ||
|
||
return new Response(script, { | ||
headers: { "Content-Type": "text/html" }, | ||
}) | ||
} catch (err) { | ||
// If we hit an error we'll handle that here | ||
console.log(err) | ||
return redirect("/?error=😡") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const prerender = "false" | ||
import type { APIRoute } from "astro" | ||
import { authUrl } from "./_config" | ||
|
||
export const GET: APIRoute = ({ redirect }) => { | ||
return redirect(authUrl) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably why firebase is upset