-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ch(improve): improve social login implementation
- edit login by google implementation - edit login by facebook implementation - add test - [Finish #170476231]
- Loading branch information
1 parent
1aaa309
commit c73c1b7
Showing
9 changed files
with
80 additions
and
125 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
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import passport from 'passport'; | ||
import FacebookTokenStrategy from 'passport-facebook-token'; | ||
import GooglePlusTokenStrategy from 'passport-google-plus-token'; | ||
import dotenv from 'dotenv'; | ||
import User from '../controllers/UserController'; | ||
// import passport from 'passport'; | ||
// import FacebookTokenStrategy from 'passport-facebook-token'; | ||
// import GooglePlusTokenStrategy from 'passport-google-plus-token'; | ||
// import dotenv from 'dotenv'; | ||
// import User from '../controllers/UserController'; | ||
|
||
dotenv.config(); | ||
passport.use('facebook-token', new FacebookTokenStrategy({ | ||
clientID: process.env.FACEBOOK_APP_ID, | ||
clientSecret: process.env.FACEBOOK_APP_SECRET | ||
}, User.facebookCallBack)); | ||
// dotenv.config(); | ||
// passport.use('facebook-token', new FacebookTokenStrategy({ | ||
// clientID: process.env.FACEBOOK_APP_ID, | ||
// clientSecret: process.env.FACEBOOK_APP_SECRET | ||
// }, User.facebookCallBack)); | ||
|
||
passport.use(new GooglePlusTokenStrategy({ | ||
clientID: process.env.GOOGLE_APP_ID, | ||
clientSecret: process.env.GOOGLE_APP_SECRET | ||
}, User.googleCallBack)); | ||
// passport.use(new GooglePlusTokenStrategy({ | ||
// clientID: process.env.GOOGLE_APP_ID, | ||
// clientSecret: process.env.GOOGLE_APP_SECRET | ||
// }, User.googleCallBack)); |
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 |
---|---|---|
@@ -1,68 +1,34 @@ | ||
import chaiHttp from 'chai-http'; | ||
import sinon from 'sinon'; | ||
import sinonChai from 'sinon-chai'; | ||
import { describe, it } from 'mocha'; | ||
import profile from './mock/googleProfile'; | ||
import UserController from '../controllers/UserController'; | ||
import chai from 'chai'; | ||
import app from '../index'; | ||
import mockData from './mock/mockData'; | ||
|
||
|
||
const chai = require('chai'); | ||
|
||
const { socialUser, socialToken } = mockData; | ||
const { facebook_feke_user, google_feke_user } = mockData; | ||
|
||
chai.use(chaiHttp); | ||
chai.use(sinonChai); | ||
const { expect } = chai; | ||
|
||
|
||
describe('Oauthentication CallBack', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
|
||
it('Should return status 200', async () => { | ||
const req = { | ||
user: { | ||
socialUser | ||
} | ||
}; | ||
|
||
const res = { status() { }, json() { }, }; | ||
sinon.stub(res, 'status').returnsThis(); | ||
await UserController.OAuthgoogle(req, res); | ||
expect(res.status).to.have.been.calledWith(200); | ||
}); | ||
it('Should not signin with google a user with wrong token', (done) => { | ||
describe('Social login test', () => { | ||
it('Expect to signin with google account', (done) => { | ||
chai.request(app) | ||
.post('/api/v1/auth/google') | ||
.send(socialToken) | ||
.send(google_feke_user) | ||
.end((err, res) => { | ||
expect(res.status).eql(400); | ||
expect(res.body.message).eql('Authentication error'); | ||
expect(res.status).eql(200); | ||
expect(res.body.message).eql('Logged in with google successfully'); | ||
done(err); | ||
}); | ||
}); | ||
it('Should not signin with facebook a user with wrong token', (done) => { | ||
it('Expect to signin with facebook account', (done) => { | ||
chai.request(app) | ||
.post('/api/v1/auth/facebook') | ||
.send(socialToken) | ||
.send(facebook_feke_user) | ||
.end((err, res) => { | ||
expect(res.status).eql(400); | ||
expect(res.body.message).eql('Authentication error'); | ||
expect(res.status).eql(200); | ||
expect(res.body.message).eql('Logged in with facebook successfully'); | ||
done(err); | ||
}); | ||
}); | ||
it('OAuthCallback should return User object', async (done) => { | ||
const accessToken = 'xx-xx-xx'; | ||
const refreshToken = 'xx-xx-xx'; | ||
const cb = sinon.spy(); | ||
UserController.googleCallBack(accessToken, refreshToken, profile, cb); | ||
expect(cb.withArgs({ | ||
socialUser | ||
})); | ||
done(); | ||
}); | ||
}); |
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