This repository has been archived by the owner on Dec 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: live admin page authenticates with github #87
Open
hetd54
wants to merge
13
commits into
main
Choose a base branch
from
github-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
940a8b5
chore: node ssr rendering
hetd54 e3f4574
feat: api endpoints for auth
hetd54 43f81e2
chore: base_url live site
hetd54 77ca364
chore: pass host from astro
hetd54 aaf2feb
fix: return response
hetd54 ef8e69b
chore: move api to src
hetd54 ae18038
fix: message type
hetd54 cc272aa
fix: script tags for accessing window on client for astro
hetd54 ed18095
test: OliverSpeir/astro-decap-starter-ssr/
hetd54 7c1acbe
fix: remove previews
hetd54 8aca097
fix: remove preview body
hetd54 9dfcf36
chore: remove staticcms
hetd54 24c2881
fix: remove media_library
hetd54 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Large diffs are not rendered by default.
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
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.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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> |
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,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" |
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,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=😡") | ||
} | ||
} |
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,7 @@ | ||
export const prerender = "false" | ||
import type { APIRoute } from "astro" | ||
import { authUrl } from "./_config" | ||
|
||
export const GET: APIRoute = ({ redirect }) => { | ||
return redirect(authUrl) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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