Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oauth): add GitHub oauth #2395

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export class Generator extends Base {
message: 'Would you like to include additional oAuth strategies?',
when: answers => answers.auth,
choices: [{
value: 'githubAuth',
name: 'GitHub',
checked: false
}, {
value: 'googleAuth',
name: 'Google',
checked: false
Expand Down Expand Up @@ -317,6 +321,7 @@ export class Generator extends Base {
});
}
insight.track('oauth', !!this.filters.oauth);
insight.track('github-oauth', !!this.filters['githubeAuth']);
insight.track('google-oauth', !!this.filters['googleAuth']);
insight.track('facebook-oauth', !!this.filters['facebookAuth']);
insight.track('twitter-oauth', !!this.filters['twitterAuth']);
Expand Down
2 changes: 1 addition & 1 deletion src/test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('angular-fullstack:app', function() {
testing: 'jasmine',
odms: ['mongoose'],
auth: true,
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth'],
oauth: ['twitterAuth', 'facebookAuth', 'googleAuth', 'githubAuth'],
socketio: true,
bootstrap: true,
uibootstrap: true
Expand Down
17 changes: 12 additions & 5 deletions templates/app/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@
"connect-mongo": "^1.2.1",<% } %><% if(filters.sequelize) { %>
"sequelize": "^3.23.6",
"sqlite3": "~3.1.1",
"express-sequelize-session": "0.4.0",<% } %><% if(filters.auth) { %>
"express-sequelize-session": "0.4.0",<% } %>
<%_ if(filters.auth) { -%>
"jsonwebtoken": "^7.0.0",
"express-jwt": "^5.0.0",
"passport": "~0.3.0",
"passport-local": "^1.0.0",<% } %><% if(filters.facebookAuth) { %>
"passport-facebook": "^2.0.0",<% } %><% if(filters.twitterAuth) { %>
"passport-twitter": "^1.0.3",<% } %><% if(filters.googleAuth) { %>
"passport-google-oauth20": "^1.0.0",<% } %><% if(filters.socketio) { %>
"passport-local": "^1.0.0",<% } %>
<%_ if(filters.facebookAuth) { -%>
"passport-facebook": "^2.0.0",<% } %>
<%_ if(filters.twitterAuth) { -%>
"passport-twitter": "^1.0.3",<% } %>
<%_ if(filters.googleAuth) { -%>
"passport-google-oauth20": "^1.0.0",<% } %>
<%_ if(filters.githubAuth) { -%>
"passport-github": "^1.1.0",<% } %>
<%_ if(filters.socketio) { -%>
"socket.io": "^1.3.5",
"socket.io-client": "^1.3.5",
"socketio-jwt": "^4.2.0",<% } %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<% if (!filters.bootstrap) { if (filters.facebookAuth) { %>.btn-facebook {
<%_ if(!filters.bootstrap) { -%>
<%_ if(filters.facebookAuth) { -%>
.btn-facebook {
color: #fff;
background-color: #3B5998;
border-color: #133783;
}
<% } if (filters.googleAuth) { %>.btn-google {
}<% } %>
<%_ if(filters.googleAuth) { -%>
.btn-google {
color: #fff;
background-color: #dd4b39;
border-color: #c53727;
}
<% } if (filters.twitterAuth) { %>.btn-twitter {
}<% } %>
<%_ if(filters.twitterAuth) { -%>
.btn-twitter {
color: #fff;
background-color: #2daddc;
border-color: #0271bf;
}
<% } %>.btn-github {
}<% } %>
<%_ if(filters.githubAuth) { -%>
.btn-github {
color: #fff;
background-color: #fafafa;
border-color: #ccc;
background-color: #444444;
}<% } %>
<% } %>
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<% if(filters.facebookAuth) { %><a class="btn-block" (click)="loginOauth('facebook')" class="btn<% if (filters.bootstrap) { %> btn-social<% } %> btn-facebook">
<%_ if(filters.facebookAuth) { -%>
<a class="btn-block" (click)="loginOauth('facebook')" class="btn<% if(filters.bootstrap) { %> btn-social<% } %> btn-facebook">
<i class="fa fa-facebook"></i>
Connect with Facebook
</a>
<% } if (filters.googleAuth) { %><a class="btn-block" (click)="loginOauth('google')" class="btn<% if (filters.bootstrap) { %> btn-social<% } %> btn-google">
</a><% } %>
<%_ if(filters.googleAuth) { -%>
<a class="btn-block" (click)="loginOauth('google')" class="btn<% if(filters.bootstrap) { %> btn-social<% } %> btn-google">
<i class="fa fa-google-plus"></i>
Connect with Google+
</a>
<% } if (filters.twitterAuth) { %><a class="btn-block" (click)="loginOauth('twitter')" class="btn<% if (filters.bootstrap) { %> btn-social<% } %> btn-twitter">
</a><% } %>
<%_ if(filters.twitterAuth) { -%>
<a class="btn-block" (click)="loginOauth('twitter')" class="btn<% if(filters.bootstrap) { %> btn-social<% } %> btn-twitter">
<i class="fa fa-twitter"></i>
Connect with Twitter
</a><% } %>
<%_ if(filters.githubAuth) { -%>
<a class="btn-block" (click)="loginOauth('github')" class="btn<% if(filters.bootstrap) { %> btn-social<% } %> btn-github">
<i class="fa fa-github"></i>
Connect with GitHub
</a><% } %>
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<% if (!filters.bootstrap) { if (filters.facebookAuth) { %>.btn-facebook {
<%_ if(!filters.bootstrap) { -%>
<%_ if(filters.facebookAuth) { -%>
.btn-facebook {
color: #fff;
background-color: #3B5998;
border-color: #133783;
}
<% } if (filters.googleAuth) { %>.btn-google {
}<% } %>
<%_ if(filters.googleAuth) { -%>
.btn-google {
color: #fff;
background-color: #dd4b39;
border-color: #c53727;
}
<% } if (filters.twitterAuth) { %>.btn-twitter {
}<% } %>
<%_ if(filters.twitterAuth) { -%>
.btn-twitter {
color: #fff;
background-color: #2daddc;
border-color: #0271bf;
}
<% } %>.btn-github {
}<% } %>
<%_ if(filters.githubAuth) { -%>
.btn-github {
color: #fff;
background-color: #fafafa;
border-color: #ccc;
background-color: #444444;
}<% } %>
<% } %>
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
<% if (!filters.bootstrap) { if (filters.facebookAuth) { %>.btn-facebook {
<%_ if(!filters.bootstrap) { -%>
<%_ if(filters.facebookAuth) { -%>
.btn-facebook {
color: #fff;
background-color: #3B5998;
border-color: #133783;
}
<% } if (filters.googleAuth) { %>.btn-google {
}<% } %>
<%_ if(filters.googleAuth) { -%>
.btn-google {
color: #fff;
background-color: #dd4b39;
border-color: #c53727;
}
<% } if (filters.twitterAuth) { %>.btn-twitter {
}<% } %>
<%_ if(filters.twitterAuth) { -%>
.btn-twitter {
color: #fff;
background-color: #2daddc;
border-color: #0271bf;
}
<% } %>.btn-github {
}<% } %>
<%_ if(filters.githubAuth) { -%>
.btn-github {
color: #fff;
background-color: #fafafa;
border-color: #ccc;
background-color: #444444;
}<% } %>
<% } %>
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<% if (!filters.bootstrap) { if (filters.facebookAuth) { %>.btn-facebook
<%_ if(!filters.bootstrap) { -%>
<%_ if(filters.facebookAuth) { -%>
.btn-facebook
color #fff
background-color #3B5998
border-color #133783
<% } if (filters.googleAuth) { %>.btn-google
border-color #133783<% } %>
<%_ if(filters.googleAuth) { -%>
.btn-google
color #fff
background-color #dd4b39
border-color #c53727
<% } if (filters.twitterAuth) { %>.btn-twitter
border-color #c53727<% } %>
<%_ if(filters.twitterAuth) { -%>
.btn-twitter
color #fff
background-color #2daddc
border-color #0271bf
<% } %>.btn-github
border-color #0271bf<% } %>
<%_ if(filters.githubAuth) { -%>
.btn-github
color #fff
background-color #fafafa
border-color #ccc<% } %>
background-color #444444<% } %>
<% } %>
3 changes: 3 additions & 0 deletions templates/app/e2e/account(auth)/login/login.spec(jasmine).js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ describe('Login View', function() {
expect(page.form.oauthButtons.google.getAttribute('class')).toMatch('btn-block');<% } if (filters.twitterAuth) { %>
expect(page.form.oauthButtons.twitter.getText()).toBe('Connect with Twitter');
expect(page.form.oauthButtons.twitter.getAttribute('class')).toMatch('btn-block');<% } %>
<%_ if (filters.githubAuth) { -%>
expect(page.form.oauthButtons.github.getText()).toBe('Connect with GitHub');
expect(page.form.oauthButtons.github.getAttribute('class')).toMatch('btn-block');<% } %>
});<% } %>

describe('with local auth', function() {
Expand Down
3 changes: 3 additions & 0 deletions templates/app/e2e/account(auth)/login/login.spec(mocha).js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ describe('Login View', function() {
<%= expect() %>page.form.oauthButtons.google.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if (filters.twitterAuth) { %>
<%= expect() %>page.form.oauthButtons.twitter.getText()<%= to() %>.eventually.equal('Connect with Twitter');
<%= expect() %>page.form.oauthButtons.twitter.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } %>
<%_ if (filters.githubAuth) { -%>
<%= expect() %>page.form.oauthButtons.github.getText()<%= to() %>.eventually.equal('Connect with GitHub');
<%= expect() %>page.form.oauthButtons.github.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } %>
});<% } %>

describe('with local auth', function() {
Expand Down
19 changes: 11 additions & 8 deletions templates/app/e2e/account(auth)/signup/signup.spec(jasmine).js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var config = browser.params;<% if (filters.mongooseModels) { %>
var UserModel = require(config.serverConfig.root + '/server/api/user/user.model').default;<% } %><% if (filters.sequelizeModels) { %>
var config = browser.params;<% if(filters.mongooseModels) { %>
var UserModel = require(config.serverConfig.root + '/server/api/user/user.model').default;<% } %><% if(filters.sequelizeModels) { %>
var UserModel = require(config.serverConfig.root + '/server/sqldb').User;<% } %>

describe('Signup View', function() {
Expand Down Expand Up @@ -38,22 +38,25 @@ describe('Signup View', function() {
expect(page.form.confirmPassword.getAttribute('name')).toBe('confirmPassword');
expect(page.form.submit.getAttribute('type')).toBe('submit');
expect(page.form.submit.getText()).toBe('Sign up');
});<% if (filters.oauth) { %>
});<% if(filters.oauth) { %>

it('should include oauth buttons with correct classes applied', function() {<% if (filters.facebookAuth) { %>
it('should include oauth buttons with correct classes applied', function() {<% if(filters.facebookAuth) { %>
expect(page.form.oauthButtons.facebook.getText()).toBe('Connect with Facebook');
expect(page.form.oauthButtons.facebook.getAttribute('class')).toMatch('btn-block');<% } if (filters.googleAuth) { %>
expect(page.form.oauthButtons.facebook.getAttribute('class')).toMatch('btn-block');<% } if(filters.googleAuth) { %>
expect(page.form.oauthButtons.google.getText()).toBe('Connect with Google+');
expect(page.form.oauthButtons.google.getAttribute('class')).toMatch('btn-block');<% } if (filters.twitterAuth) { %>
expect(page.form.oauthButtons.google.getAttribute('class')).toMatch('btn-block');<% } if(filters.twitterAuth) { %>
expect(page.form.oauthButtons.twitter.getText()).toBe('Connect with Twitter');
expect(page.form.oauthButtons.twitter.getAttribute('class')).toMatch('btn-block');<% } %>
<%_ if(filters.githubAuth) { -%>
expect(page.form.oauthButtons.github.getText()).toBe('Connect with GitHub');
expect(page.form.oauthButtons.github.getAttribute('class')).toMatch('btn-block');<% } %>
});<% } %>

describe('with local auth', function() {

beforeAll(function(done) {
<% if (filters.mongooseModels) { %>UserModel.remove().then(done);<% }
if (filters.sequelizeModels) { %>UserModel.destroy({ where: {} }).then(done);<% } %>
<% if(filters.mongooseModels) { %>UserModel.remove().then(done);<% }
if(filters.sequelizeModels) { %>UserModel.destroy({ where: {} }).then(done);<% } %>
});

it('should signup a new user, log them in, and redirecting to "/"', function() {
Expand Down
23 changes: 13 additions & 10 deletions templates/app/e2e/account(auth)/signup/signup.spec(mocha).js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var config = browser.params;<% if (filters.mongooseModels) { %>
var UserModel = require(config.serverConfig.root + '/server/api/user/user.model').default;<% } %><% if (filters.sequelizeModels) { %>
var config = browser.params;<% if(filters.mongooseModels) { %>
var UserModel = require(config.serverConfig.root + '/server/api/user/user.model').default;<% } %><% if(filters.sequelizeModels) { %>
var UserModel = require(config.serverConfig.root + '/server/sqldb').User;<% } %>

describe('Signup View', function() {
Expand All @@ -26,8 +26,8 @@ describe('Signup View', function() {
});

after(function() {
<% if (filters.mongooseModels) { %>return UserModel.remove();<% }
if (filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %>
<% if(filters.mongooseModels) { %>return UserModel.remove();<% }
if(filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %>
});

it('should include signup form with correct inputs and submit button', function() {
Expand All @@ -41,22 +41,25 @@ describe('Signup View', function() {
<%= expect() %>page.form.confirmPassword.getAttribute('name')<%= to() %>.eventually.equal('confirmPassword');
<%= expect() %>page.form.submit.getAttribute('type')<%= to() %>.eventually.equal('submit');
<%= expect() %>page.form.submit.getText()<%= to() %>.eventually.equal('Sign up');
});<% if (filters.oauth) { %>
});<% if(filters.oauth) { %>

it('should include oauth buttons with correct classes applied', function() {<% if (filters.facebookAuth) { %>
it('should include oauth buttons with correct classes applied', function() {<% if(filters.facebookAuth) { %>
<%= expect() %>page.form.oauthButtons.facebook.getText()<%= to() %>.eventually.equal('Connect with Facebook');
<%= expect() %>page.form.oauthButtons.facebook.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if (filters.googleAuth) { %>
<%= expect() %>page.form.oauthButtons.facebook.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if(filters.googleAuth) { %>
<%= expect() %>page.form.oauthButtons.google.getText()<%= to() %>.eventually.equal('Connect with Google+');
<%= expect() %>page.form.oauthButtons.google.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if (filters.twitterAuth) { %>
<%= expect() %>page.form.oauthButtons.google.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } if(filters.twitterAuth) { %>
<%= expect() %>page.form.oauthButtons.twitter.getText()<%= to() %>.eventually.equal('Connect with Twitter');
<%= expect() %>page.form.oauthButtons.twitter.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } %>
<%_ if(filters.githubAuth) { -%>
<%= expect() %>page.form.oauthButtons.github.getText()<%= to() %>.eventually.equal('Connect with GitHub');
<%= expect() %>page.form.oauthButtons.github.getAttribute('class')<%= to() %>.eventually.contain('btn-block');<% } %>
});<% } %>

describe('with local auth', function() {

before(function() {
<% if (filters.mongooseModels) { %>return UserModel.remove();<% }
if (filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %>
<% if(filters.mongooseModels) { %>return UserModel.remove();<% }
if(filters.sequelizeModels) { %>return UserModel.destroy({ where: {} });<% } %>
})

it('should signup a new user, log them in, and redirecting to "/"', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
* https://docs.google.com/presentation/d/1B6manhG0zEXkC-H-tPo2vwU06JhL8w9-XCF9oehXzAQ
*/

'use strict';

var OauthButtons = function() {
var oauthButtons = this.oauthButtons = element(by.css('oauth-buttons'));<% if (filters.facebookAuth) { %>
oauthButtons.facebook = oauthButtons.element(by.css('.btn<% if (filters.bootstrap) { %>.btn-social<% } %>.btn-facebook'));<% } if (filters.googleAuth) { %>
oauthButtons.google = oauthButtons.element(by.css('.btn<% if (filters.bootstrap) { %>.btn-social<% } %>.btn-google'));<% } if (filters.twitterAuth) { %>
oauthButtons.twitter = oauthButtons.element(by.css('.btn<% if (filters.bootstrap) { %>.btn-social<% } %>.btn-twitter'));<% } %>
var oauthButtons = this.oauthButtons = element(by.css('oauth-buttons'));
<%_ if(filters.facebookAuth) { -%>
oauthButtons.facebook = oauthButtons.element(by.css('.btn<% if(filters.bootstrap) { %>.btn-social<% } %>.btn-facebook'));<% } %>
<%_ if(filters.googleAuth) { -%>
oauthButtons.google = oauthButtons.element(by.css('.btn<% if(filters.bootstrap) { %>.btn-social<% } %>.btn-google'));<% } %>
<%_ if(filters.twitterAuth) { -%>
oauthButtons.twitter = oauthButtons.element(by.css('.btn<% if(filters.bootstrap) { %>.btn-social<% } %>.btn-twitter'));<% } %>
<%_ if(filters.githubAuth) { -%>
oauthButtons.github = oauthButtons.element(by.css('.btn<% if(filters.bootstrap) { %>.btn-social<% } %>.btn-github'));<% } %>
};

module.exports = new OauthButtons();
14 changes: 10 additions & 4 deletions templates/app/server/api/user(auth)/user.model(mongooseModels).js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ var UserSchema = new Schema({
}<% } else { %>true<% } %>
},
provider: String,
salt: String<% if(filters.oauth) { %>,<% if(filters.facebookAuth) { %>
facebook: {},<% } %><% if(filters.twitterAuth) { %>
twitter: {},<% } %><% if(filters.googleAuth) { %>
salt: String,
<%_ if(filters.oauth) { -%>
<%_ if(filters.facebookAuth) { -%>
facebook: {},<% } %>
<%_ if(filters.twitterAuth) { -%>
twitter: {},<% } %>
<%_ if(filters.googleAuth) { -%>
google: {},<% } %>
github: {}<% } %>
<%_ if(filters.githubAuth) { -%>
github: {},
<% } %>
});

/**
Expand Down