-
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.
Feature(OauthTwitter): Login user via social media
- WIll allow user to login via twitter [Delivers #164489928]
- Loading branch information
1 parent
edd972c
commit 8c39a28
Showing
10 changed files
with
110 additions
and
3 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
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,16 @@ | ||
import passport from 'passport'; | ||
import twitterStrategy from './passport-twitter'; | ||
import twitteruser from './serialize'; | ||
/** | ||
* Get user information from the strategy and then pass it to serialize class | ||
*/ | ||
class Authentication { | ||
/** | ||
* Authentication constructor | ||
*/ | ||
constructor() { | ||
this.twitter = passport.use(twitterStrategy); | ||
this.serializeTwitteruser = twitteruser(passport, this.user); | ||
} | ||
} | ||
export default Authentication; |
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,21 @@ | ||
import twitterStrategy from 'passport-twitter'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
const { TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_CALLBACK_URL } = process.env; | ||
|
||
const twStrategy = new twitterStrategy( | ||
{ | ||
consumerKey: TWITTER_CONSUMER_KEY, | ||
consumerSecret: TWITTER_CONSUMER_SECRET, | ||
callbackURL: TWITTER_CALLBACK_URL | ||
}, | ||
(token, tokenSecret, profile, done) => { | ||
const userTwitter = { | ||
username: profile._json.name | ||
}; | ||
done(null, userTwitter); | ||
} | ||
); | ||
|
||
export default twStrategy; |
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,12 @@ | ||
const twitterUser = (passport, user) => { | ||
passport.serializeUser((userTwitwer, done) => { | ||
done(null, userTwitwer.username); | ||
}); | ||
passport.deserializeUser((username, done) => { | ||
user.findByPk(username).then((userTwitwer) => { | ||
done(null, userTwitwer); | ||
}) | ||
.catch(err => done(err, false)); | ||
}); | ||
}; | ||
export default twitterUser; |
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,14 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import passport from 'passport'; | ||
import express from 'express'; | ||
import authentication from '../../../middlewares/authentication'; | ||
import user from '../../../controllers/user'; | ||
|
||
const TwitwerStrategy = new authentication(); | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/login/twitter', passport.authenticate('twitter',)); | ||
router.get('/login/twitter/redirect', passport.authenticate('twitter', { session: false }), user.twitterLogin); | ||
|
||
export default router; |
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