Last active
December 4, 2019 12:54
-
-
Save yoelmacia/21493452fa1790ad5684a140461ccb60 to your computer and use it in GitHub Desktop.
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
const express = require("express"); | |
const app = express(); | |
const port = process.env.PORT || 3000; | |
const axios = require("axios"); | |
app.get("/", (req, res) => { | |
res.sendFile("index.html", { root: __dirname }); | |
}); | |
app.get("/user/signin/callback", (req, res) => { | |
const { query } = req; | |
const { code } = query; | |
if (!code) { | |
return res.send({ | |
success: "false", | |
message: "Error, no code" | |
}); | |
} | |
axios | |
.post("https://github.com/login/oauth/access_token", { | |
client_id: "<your_client_id>", | |
client_secret: "<your_client_secret>", | |
code, | |
headers: { | |
Accept: "application/json" | |
} | |
}) | |
.then(response => { | |
const data = response.data; | |
token = data.split("&")[0].split("=")[1]; | |
res.send(token); | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
}); | |
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