Created
April 26, 2019 16:30
-
-
Save zprima/5cdfbe8b7b68dcd00d71333ed6c4b7c9 to your computer and use it in GitHub Desktop.
medium_p4_c2
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
| const CLIENT_ID = 'YOUR CLIENT HERE'; | |
| const CLIENT_SECRET = 'YOUR SECRET HERE'; | |
| const express = require('express'); | |
| const cors = require('cors') | |
| const bodyParser = require('body-parser') | |
| const { google } = require('googleapis'); | |
| const app = express(); | |
| const port = 8080; | |
| const oauth2Client = new google.auth.OAuth2( | |
| CLIENT_ID, | |
| CLIENT_SECRET, | |
| 'postmessage' | |
| ); | |
| app.use(cors()); | |
| // parse application/x-www-form-urlencoded | |
| app.use(bodyParser.urlencoded({ extended: false })) | |
| // parse application/json | |
| app.use(bodyParser.json()) | |
| // ROUTES | |
| app.post('/auth/google', (req, res) => { | |
| var code = req.body.code; | |
| console.log(`Auth google endpoint: ${code}`) | |
| oauth2Client.getToken(code, function (err, tokens) { | |
| if (err) { | |
| res.status(422).json({ err: err }); | |
| } else { | |
| res.json({ token: tokens.access_token }); | |
| } | |
| }); | |
| }) | |
| app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment