Created
May 5, 2021 15:19
-
-
Save lxhom/a632aca1af4cdc74a83baf6b80077350 to your computer and use it in GitHub Desktop.
Revisions
-
lxhom created this gist
May 5, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ const express = require('express'); const lwt = require("login-with-twitter"); const app = express() // twitter oauth const tw = new lwt({ consumerKey: '[#yourkey]', consumerSecret: '[#yourkey]', callbackUrl: 'https://[#your url]/callback' }); app.get("/callback", (req, res) => { res.send(` <script> location.href = location.href.replace("/c?", "/gen?") + "&token_secret=" + localStorage.tokenSecret; </script> `); }); app.get("/generate-token", (req, res) => { tw.callback({ oauth_token: req.query.oauth_token, oauth_verifier: req.query.oauth_verifier }, req.query.token_secret, (err, user) => { if (err) { throw err; } // auth tokens are stored in the user object. edit this part and add a logged in page res.send(` <script> location.href = "/logged-in?authdata=${escape(JSON.stringify(user))}" </script> `); }); }); app.get("/start-login", (req, res) => { tw.login((err, tokenSecret, url) => { if (err) { throw err; } res.send(` <script> localStorage.tokenSecret = "${tokenSecret}"; location.href = "${url}"; </script> `); }); });