-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd0fc58
commit 5ac8942
Showing
6 changed files
with
36 additions
and
5 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 |
---|---|---|
|
@@ -40,6 +40,7 @@ jobs: | |
uses: 73h/[email protected] | ||
env: | ||
POSTGRES_STRING: ${{ secrets.POSTGRES_STRING }} | ||
PROJECT_ID: ${{ secrets.PROJECT_ID }} | ||
with: | ||
app_yaml_path: app.yaml | ||
|
||
|
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,29 @@ | ||
import { OAuth2Client } from 'google-auth-library'; | ||
|
||
const oAuth2Client = new OAuth2Client(); | ||
|
||
const validateGoogleToken = async (req, res, next) => { | ||
const authHeader = req.header('Authorization'); | ||
if (!authHeader) { | ||
return res.status(401).json({ message: 'Unauthorized' }); | ||
} | ||
|
||
const token = authHeader.split(' ')[1]; // Bearer <token> | ||
try { | ||
// Verify the access token's payload: | ||
const tokenInfo = await oAuth2Client.getTokenInfo(token); | ||
|
||
if (tokenInfo.email !== `solana-devnet-faucet-fe@${process.env.PROJECT_ID}.iam.gserviceaccount.com`) { | ||
return res.status(403).json({ message: 'Forbidden: Invalid audience' }); | ||
} | ||
|
||
// Proceed if valid token | ||
req.user = tokenInfo; // Attach tokenInfo data (like subject) to req.user | ||
next(); | ||
} catch (error) { | ||
console.log("Error with Auth", error); | ||
res.status(403).json({ message: 'Forbidden' }); | ||
} | ||
}; | ||
|
||
export { validateGoogleToken }; |