-
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 #13 from ChangePlusPlusVandy/lyton/22
feat: basic auth with auth0
- Loading branch information
Showing
21 changed files
with
393 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,5 @@ | |
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
**/**/.env |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
import { | ||
InvalidTokenError, | ||
UnauthorizedError, | ||
} from "express-oauth2-jwt-bearer"; | ||
|
||
export const errorHandler = ( | ||
error: any, | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
console.log("Auth Error"); | ||
|
||
if (error instanceof InvalidTokenError) { | ||
const message = "Bad credentials"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
if (error instanceof UnauthorizedError) { | ||
const message = "Requires authentication"; | ||
|
||
response.status(error.status).json({ message }); | ||
|
||
return; | ||
} | ||
|
||
const status = 500; | ||
const message = "Internal Server Error"; | ||
|
||
response.status(status).json({ message }); | ||
}; |
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,21 @@ | ||
import { auth } from "express-oauth2-jwt-bearer"; | ||
import dotenv from "dotenv"; | ||
import path from "path"; | ||
|
||
dotenv.config({ path: path.resolve(__dirname, "../.env") }); | ||
|
||
const auth0Domain = process.env.AUTH0_DOMAIN; | ||
const auth0Audience = process.env.AUTH0_AUDIENCE; | ||
|
||
try { | ||
if (!auth0Domain || !auth0Audience) { | ||
throw new Error("AUTH0_DOMAIN or AUTH0_AUDIENCE is not set"); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
|
||
export const validateAccessToken = auth({ | ||
issuerBaseURL: `https://${auth0Domain}`, | ||
audience: auth0Audience, | ||
}); |
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,11 @@ | ||
import { Request, Response, NextFunction } from "express"; | ||
|
||
export const notFoundHandler = ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction, | ||
) => { | ||
const message = "Not Found"; | ||
|
||
response.status(404).json({ message }); | ||
}; |
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,6 @@ | ||
REACT_APP_API_URL = http://127.0.0.1:8000 | ||
|
||
# auth | ||
REACT_APP_AUTH0_DOMAIN=##check notion## | ||
REACT_APP_AUTH0_CLIENT_ID=##check notion## | ||
REACT_APP_AUTH0_CALLBACK_URL=http://localhost:3000/callback |
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
Oops, something went wrong.