-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(socialLogin google):socialLogin using google
setup social Login using passport google [Delivers #167574995]
- Loading branch information
Adekoreday
committed
Aug 7, 2019
1 parent
74c3019
commit 3bb0149
Showing
9 changed files
with
160 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import passport from 'passport'; | ||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20'; | ||
import passportCallback from '../middlewares/passportCallback'; | ||
|
||
export default () => { | ||
passport.use( | ||
new GoogleStrategy( | ||
{ | ||
clientID: process.env.GOOGLE_CLIENT_ID, | ||
clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
callbackURL: process.env.GOOGLE_REDIRECT_URL | ||
}, | ||
passportCallback | ||
) | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import chai from 'chai'; | ||
import sinon from 'sinon'; | ||
import google from '../../server/helpers/google'; | ||
import Auth from '../../server/controllers/Auth'; | ||
import models from '../../server/database/models/index'; | ||
import passportCallback from '../../server/middlewares/passportCallback'; | ||
import { request2, users, profile } from './__mocks_'; | ||
|
||
const { expect } = chai; | ||
const { User, Session } = models; | ||
describe('google login test', () => { | ||
context('when a valid user want to login with google', () => { | ||
it('logs in such user successfully', async () => { | ||
const res = { status() {}, json() {} }; | ||
const status = sinon.stub(res, 'status').returnsThis(); | ||
const json = sinon.stub(res, 'json').returnsThis(); | ||
const Sessions = sinon.stub(Session, 'create').returns(false); | ||
const findOrCreate = sinon.stub(User, 'findOrCreate').returns(users); | ||
await Auth.socialLogin(request2, res); | ||
sinon.assert.calledOnce(status); | ||
sinon.assert.calledOnce(json); | ||
Sessions.restore(); | ||
findOrCreate.restore(); | ||
}); | ||
}); | ||
context('when an invalid user want to login with google', () => { | ||
it('returns error message', () => { | ||
const result = passportCallback(null, null, profile, (err, next) => next); | ||
expect(result).to.be.instanceOf(Object); | ||
expect(result.error).to.be.equal('Auth failed'); | ||
}); | ||
}); | ||
context('when a valid user wants to login using google', () => { | ||
it('logs in the user successfully', async () => { | ||
const response = google(); | ||
expect(response).to.equal(undefined); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.