-
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
Add user verification for server API #37
Closed
Closed
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
32d1ad1
Send UID to server for auth
kyeah bcd08ea
cleanup
kyeah d2e549c
cleanup
kyeah b84b64d
Remove console log
kyeah 21b50a7
Add comment
kyeah fdee462
Run formatter
kyeah 205997a
Merge branch 'main' of https://github.com/soft-networks/is-this-thing…
kyeah 74faee5
remove unused method
kyeah 651e5df
Fix build error
kyeah 8e7cecd
Merge branch 'main' of https://github.com/soft-networks/is-this-thing…
kyeah 009eddf
fix webhook
kyeah 612fdf1
Merge branch 'main' into kev/validate-admins
kyeah 4f6d6b8
Merge branch 'main' into kev/validate-admins
kyeah 5eb0b13
Update streamGate.tsx
kyeah 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
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
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,41 @@ | ||
import { RequestHandler } from "express"; | ||
import { firebaseAuth } from "./firebase-init.js"; | ||
import { isAdminForAnyRoom } from "./firestore-api.js"; | ||
import { logError } from "./logger.js"; | ||
|
||
/** | ||
* Middleware to ensure that the caller has provided admin credentials. | ||
* An admin is any user who has been assigned as an admin to any room in Firestore. | ||
*/ | ||
export const verifyThingAdmin: RequestHandler = async (req, res, next) => { | ||
const bearer = req.headers.authorization; | ||
|
||
if (!bearer) { | ||
logError("No ID token provided for request"); | ||
return res.sendStatus(403); | ||
} | ||
|
||
const parts = bearer.split("Bearer "); | ||
if (parts.length <= 1) { | ||
logError("Invalid ID token provided for request"); | ||
return res.sendStatus(403); | ||
} | ||
|
||
const idToken = parts[1]; | ||
|
||
try { | ||
const decodedToken = await firebaseAuth.verifyIdToken(idToken) | ||
const uid = decodedToken.uid; | ||
|
||
const isAdmin = await isAdminForAnyRoom(uid); | ||
if (isAdmin) { | ||
return next(); | ||
} else { | ||
logError(`User with ID ${uid} is not an admin for any rooms`); | ||
} | ||
} catch (err) { | ||
logError(`Failed to verify auth token: ${err}`) | ||
} | ||
|
||
return res.sendStatus(403); | ||
} |
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
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.
I tried to use the user from UserStore at first, but for some reason it couldn't find the
getIdToken
method.