This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
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.
Cleanup, start preaparing for React frontend (#254)
- Loading branch information
1 parent
83f69a5
commit 7476c33
Showing
9 changed files
with
627 additions
and
256 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
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
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,30 @@ | ||
import { Auth } from 'googleapis'; | ||
import { google_oauth_client_id, google_oauth_client_secret } from './config.json'; | ||
import { Application } from 'express'; | ||
|
||
const oAuth2Client = new Auth.OAuth2Client({ | ||
clientId: google_oauth_client_id, | ||
clientSecret: google_oauth_client_secret, | ||
redirectUri: 'postmessage', | ||
}, | ||
); | ||
|
||
export function registerOAuthRoutes(app: Application) { | ||
app.post('/auth/google', async (req, res) => { | ||
// exchange code for tokens | ||
const { tokens } = await oAuth2Client.getToken(req.body.code); | ||
console.log(tokens); | ||
res.json(tokens); | ||
}); | ||
|
||
app.post('/auth/google/refresh-token', async (req, res) => { | ||
const user = new Auth.UserRefreshClient( | ||
google_oauth_client_id, | ||
google_oauth_client_secret, | ||
req.body.refreshToken, | ||
); | ||
// optain new tokens | ||
const { credentials } = await user.refreshAccessToken(); | ||
res.json(credentials); | ||
}); | ||
} |
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