-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add GitHub OAuth for admin #1929
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
Draft
spaenleh
wants to merge
13
commits into
main
Choose a base branch
from
1907-github-oauth-admin
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.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
de30388
fix: add oauth with github for admins
spaenleh 2c9c386
fix: make the admin auth work
spaenleh bc57f82
fix: add documentation on how to setup the oauth app
spaenleh f236050
chore: cleanup and fix package issues and file placement
spaenleh 26223d0
fix: apply recommendations for sql schema
spaenleh 6aca11b
fix: add env vars to tests
spaenleh 887c409
fix: tests with isolation of passport instances
spaenleh c3047c9
fix(test): temporarily disabled matchOne tests because passport is no…
spaenleh 6c09f4a
fix: hang with callback
spaenleh 8606f6b
fix: comments
spaenleh c39f6a7
fix: tests
spaenleh e59111f
fix: remove fp
spaenleh 8972ffb
chore(test): does not work
spaenleh 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 @@ | ||
| import { getEnv } from './env'; | ||
| import { requiredEnvVar } from './helpers'; | ||
|
|
||
| // ensure env is setup | ||
| getEnv(); | ||
|
|
||
| // GitHub OAuth app secrets | ||
| // to generate these values go to: Settings -> Developer Settings -> OAuth Apps -> New OAuth app | ||
| // the callback url should be <your-origin>/admin/auth/github/callback | ||
| // so for local developement: http://localhost:3000/admin/auth/github/callback | ||
| export const GITHUB_CLIENT_ID = requiredEnvVar('GITHUB_CLIENT_ID'); | ||
| export const GITHUB_CLIENT_SECRET = requiredEnvVar('GITHUB_CLIENT_SECRET'); |
This file contains hidden or 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,12 @@ | ||
| import { getEnv } from './env'; | ||
|
|
||
| getEnv(); | ||
|
|
||
| ///////////////////////////////////// | ||
| // Database Environement Variables // | ||
| ///////////////////////////////////// | ||
| // Can be undefined, so tests can run without setting it. | ||
| export const DB_CONNECTION_POOL_SIZE: number = +process.env.DB_CONNECTION_POOL_SIZE! || 10; | ||
| export const DB_READ_REPLICA_CONNECTIONS: string[] = process.env.DB_READ_REPLICA_CONNECTIONS | ||
| ? process.env.DB_READ_REPLICA_CONNECTIONS?.split(',') | ||
| : []; |
This file contains hidden or 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 hidden or 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,41 @@ | ||
| import { getEnv } from './env'; | ||
|
|
||
| getEnv(); | ||
|
|
||
| export const PROTOCOL = process.env.PROTOCOL || 'http'; | ||
| export const HOSTNAME = process.env.HOSTNAME || 'localhost'; | ||
| /** | ||
| * Host address the server listen on, default to 0.0.0.0 to bind to all addresses. | ||
| */ | ||
| export const HOST_LISTEN_ADDRESS = process.env.HOST_LISTEN_ADDRESS || '0.0.0.0'; | ||
|
|
||
| export const PORT = process.env.PORT ? +process.env.PORT : 3000; | ||
| export const HOST = `${PROTOCOL}://${HOSTNAME}:${PORT}`; /** | ||
| * Public url is the url where the server is hosted. Mostly used to set the cookie on the right domain | ||
| * Warning for PUBLIC_URL: | ||
| * make sure that process.env.PUBLIC_URL / HOST have the format ${PROTOCOL}://${HOSTNAME}:${PORT} | ||
| * See the following example where the format is only ${HOSTNAME}:${PORT} in which case | ||
| * it interprets the hostname as protocol and the port as the pathname. Using the complete URL | ||
| * scheme fixes that | ||
| * | ||
| * $ node | ||
| * Welcome to Node.js v16.20.1. | ||
| * Type ".help" for more information. | ||
| * > new URL('localhost:3000') | ||
| * URL { | ||
| * href: 'localhost:3000', | ||
| * origin: 'null', | ||
| * protocol: 'localhost:', | ||
| * username: '', | ||
| * password: '', | ||
| * host: '', | ||
| * hostname: '', | ||
| * port: '', | ||
| * pathname: '3000', | ||
| * search: '', | ||
| * searchParams: URLSearchParams {}, | ||
| * hash: '' | ||
| * } | ||
| * > | ||
| */ | ||
| export const PUBLIC_URL = new URL(process.env.PUBLIC_URL ?? HOST); |
This file contains hidden or 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 hidden or 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,8 @@ | ||
| CREATE TABLE "admin" ( | ||
| "github_id" varchar(15) PRIMARY KEY NOT NULL, | ||
| "github_name" varchar(39) NOT NULL, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "last_authenticated_at" timestamp with time zone, | ||
| CONSTRAINT "admin_github_id_unique" UNIQUE("github_id"), | ||
| CONSTRAINT "admin_github_name_unique" UNIQUE("github_name") | ||
| ); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.