From ce82a79b839837d37c9e385e91eefc111529860c Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Wed, 14 Jun 2023 20:25:30 +0530 Subject: [PATCH 01/10] feat: support for OAuth with GitHub --- backend/src/api/auth/authSocial.ts | 22 ++++++++++++++++++- .../src/modules/auth/pages/signin-page.vue | 10 ++++++++- .../src/modules/auth/pages/signup-page.vue | 10 ++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/src/api/auth/authSocial.ts b/backend/src/api/auth/authSocial.ts index 77951211e3..76d9fc34d2 100644 --- a/backend/src/api/auth/authSocial.ts +++ b/backend/src/api/auth/authSocial.ts @@ -1,6 +1,6 @@ import passport from 'passport' import { getServiceChildLogger } from '@crowd/logging' -import { API_CONFIG, GOOGLE_CONFIG } from '../../conf' +import { API_CONFIG, GITHUB_CONFIG, GOOGLE_CONFIG } from '../../conf' import AuthService from '../../services/auth/authService' const log = getServiceChildLogger('AuthSocial') @@ -46,6 +46,26 @@ export default (app, routes) => { })(req, res) }) } + + if (GITHUB_CONFIG.clientId) { + routes.get( + '/auth/social/github', + passport.authenticate('github', { + scope: ['user:email'], + session: false, + }), + () => { + // The request will be redirected for authentication, so this + // function will not be called. + }, + ) + + routes.get('/auth/social/github/callback', (req, res) => { + passport.authenticate('github', (err, jwtToken) => { + handleCallback(res, err, jwtToken) + })(req, res) + }) + } } function handleCallback(res, err, jwtToken) { diff --git a/frontend/src/modules/auth/pages/signin-page.vue b/frontend/src/modules/auth/pages/signin-page.vue index 2bc966eb72..ebafd888fc 100644 --- a/frontend/src/modules/auth/pages/signin-page.vue +++ b/frontend/src/modules/auth/pages/signin-page.vue @@ -117,7 +117,7 @@
-
+

diff --git a/frontend/src/modules/auth/pages/signup-page.vue b/frontend/src/modules/auth/pages/signup-page.vue index 9047018930..50b22ab194 100644 --- a/frontend/src/modules/auth/pages/signup-page.vue +++ b/frontend/src/modules/auth/pages/signup-page.vue @@ -194,7 +194,7 @@

-
+

From a0bb75edf81f7aa82d6e2f0808c1bad19f254bf0 Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Tue, 4 Jul 2023 01:23:20 +0530 Subject: [PATCH 02/10] fix: add githubStrategy for the oauth --- backend/package-lock.json | 21 +++++++ backend/package.json | 7 ++- backend/src/conf/configTypes.ts | 1 + .../middlewares/passportStrategyMiddleware.ts | 7 ++- .../auth/passportStrategies/githubStrategy.ts | 63 +++++++++++++++++++ .../auth/passportStrategies/googleStrategy.ts | 2 +- 6 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 backend/src/services/auth/passportStrategies/githubStrategy.ts diff --git a/backend/package-lock.json b/backend/package-lock.json index 77a54c2fa5..9a0b92b884 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -71,6 +71,7 @@ "openapi-comment-parser": "^1.0.0", "passport": "0.6.0", "passport-facebook": "3.0.0", + "passport-github2": "^0.1.12", "passport-google-oauth": "2.0.0", "passport-google-oauth20": "^2.0.0", "passport-slack": "0.0.7", @@ -126,6 +127,7 @@ } }, "../services/libs/alerting": { + "name": "@crowd/alerting", "version": "1.0.0", "dependencies": { "@types/node": "^20.3.1", @@ -15675,6 +15677,17 @@ "node": ">= 0.4.0" } }, + "node_modules/passport-github2": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/passport-github2/-/passport-github2-0.1.12.tgz", + "integrity": "sha512-3nPUCc7ttF/3HSP/k9sAXjz3SkGv5Nki84I05kSQPo01Jqq1NzJACgMblCK0fGcv9pKCG/KXU3AJRDGLqHLoIw==", + "dependencies": { + "passport-oauth2": "1.x.x" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/passport-google-oauth": { "version": "2.0.0", "license": "MIT", @@ -30846,6 +30859,14 @@ "passport-oauth2": "1.x.x" } }, + "passport-github2": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/passport-github2/-/passport-github2-0.1.12.tgz", + "integrity": "sha512-3nPUCc7ttF/3HSP/k9sAXjz3SkGv5Nki84I05kSQPo01Jqq1NzJACgMblCK0fGcv9pKCG/KXU3AJRDGLqHLoIw==", + "requires": { + "passport-oauth2": "1.x.x" + } + }, "passport-google-oauth": { "version": "2.0.0", "requires": { diff --git a/backend/package.json b/backend/package.json index c589426bd5..b1ae78e070 100644 --- a/backend/package.json +++ b/backend/package.json @@ -46,13 +46,13 @@ "@aws-sdk/s3-request-presigner": "^3.229.0", "@aws-sdk/url-parser": "^3.226.0", "@aws-sdk/util-format-url": "^3.226.0", + "@crowd/alerting": "file:../services/libs/alerting", "@crowd/common": "file:../services/libs/common", + "@crowd/integrations": "file:../services/libs/integrations", "@crowd/logging": "file:../services/libs/logging", "@crowd/redis": "file:../services/libs/redis", - "@crowd/integrations": "file:../services/libs/integrations", - "@crowd/types": "file:../services/libs/types", "@crowd/sqs": "file:../services/libs/sqs", - "@crowd/alerting": "file:../services/libs/alerting", + "@crowd/types": "file:../services/libs/types", "@cubejs-client/core": "^0.30.4", "@google-cloud/storage": "5.3.0", "@octokit/auth-app": "^3.6.1", @@ -105,6 +105,7 @@ "openapi-comment-parser": "^1.0.0", "passport": "0.6.0", "passport-facebook": "3.0.0", + "passport-github2": "^0.1.12", "passport-google-oauth": "2.0.0", "passport-google-oauth20": "^2.0.0", "passport-slack": "0.0.7", diff --git a/backend/src/conf/configTypes.ts b/backend/src/conf/configTypes.ts index 2f14b9b6c2..4a5b94ce34 100644 --- a/backend/src/conf/configTypes.ts +++ b/backend/src/conf/configTypes.ts @@ -138,6 +138,7 @@ export interface GithubConfiguration { webhookSecret: string isCommitDataEnabled: string globalLimit?: number + callbackUrl: string } export interface SendgridConfiguration { diff --git a/backend/src/middlewares/passportStrategyMiddleware.ts b/backend/src/middlewares/passportStrategyMiddleware.ts index 9f1fa8f8f2..cff2984e11 100644 --- a/backend/src/middlewares/passportStrategyMiddleware.ts +++ b/backend/src/middlewares/passportStrategyMiddleware.ts @@ -1,9 +1,10 @@ import passport from 'passport' import { getServiceLogger } from '@crowd/logging' -import { TWITTER_CONFIG, SLACK_CONFIG, GOOGLE_CONFIG } from '../conf' +import { TWITTER_CONFIG, SLACK_CONFIG, GOOGLE_CONFIG, GITHUB_CONFIG } from '../conf' import { getTwitterStrategy } from '../services/auth/passportStrategies/twitterStrategy' import { getSlackStrategy } from '../services/auth/passportStrategies/slackStrategy' import { getGoogleStrategy } from '../services/auth/passportStrategies/googleStrategy' +import { getGithubStrategy } from '../services/auth/passportStrategies/githubStrategy' const log = getServiceLogger() @@ -20,6 +21,10 @@ export async function passportStrategyMiddleware(req, res, next) { if (GOOGLE_CONFIG.clientId) { passport.use(getGoogleStrategy()) } + + if (GITHUB_CONFIG.clientId) { + passport.use(getGithubStrategy()) + } } catch (error) { log.error(error, 'Error getting some passport strategies!') } finally { diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts new file mode 100644 index 0000000000..458fea765b --- /dev/null +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -0,0 +1,63 @@ +import { get } from 'lodash' +import GithubStrategy from 'passport-github2' +import { getServiceChildLogger } from '@crowd/logging' +import { GITHUB_CONFIG } from '../../../conf' +import { databaseInit } from '../../../database/databaseConnection' +import AuthService from '../authService' + +const log = getServiceChildLogger('AuthSocial') + +export function getGithubStrategy(): GithubStrategy { + return new GithubStrategy( + { + clientID: GITHUB_CONFIG.clientId, + clientSecret: GITHUB_CONFIG.clientSecret, + callbackURL: GITHUB_CONFIG.callbackUrl, + }, + (accessToken, refreshToken, profile, done) => { + databaseInit() + .then((database) => { + console.log('profile', profile) + const email = get(profile, 'emails[0].value') + const displayName = get(profile, 'displayName') + const { firstName, lastName } = splitFullName(displayName) + + return AuthService.signinFromSocial( + 'github', + profile.id, + email, + true, // Github does not provide email verification in profile + firstName, + lastName, + displayName, + { database }, + ) + }) + .then((jwtToken) => { + done(null, jwtToken) + }) + .catch((error) => { + log.error(error, 'Error while handling github auth!') + done(error, null) + }) + }, + ) +} + + +// TODO: This is duplicated in googleStrategy.ts and should be moved to a common place +function splitFullName(fullName) { + let firstName + let lastName + + if (fullName && fullName.split(' ').length > 1) { + const [firstNameArray, ...lastNameArray] = fullName.split(' ') + firstName = firstNameArray + lastName = lastNameArray.join(' ') + } else { + firstName = fullName || null + lastName = null + } + + return { firstName, lastName } + } diff --git a/backend/src/services/auth/passportStrategies/googleStrategy.ts b/backend/src/services/auth/passportStrategies/googleStrategy.ts index 38ac46b6b7..dd63dc4b59 100644 --- a/backend/src/services/auth/passportStrategies/googleStrategy.ts +++ b/backend/src/services/auth/passportStrategies/googleStrategy.ts @@ -58,4 +58,4 @@ function splitFullName(fullName) { } return { firstName, lastName } -} +} \ No newline at end of file From 9a50055e10c2a97ba2b988bbb96362e9d3b3a5dd Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Fri, 7 Jul 2023 17:41:09 +0530 Subject: [PATCH 03/10] add githubStratetgy to the passport middleware --- .../middlewares/passportStrategyMiddleware.ts | 10 +++---- .../auth/passportStrategies/githubStrategy.ts | 28 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/backend/src/middlewares/passportStrategyMiddleware.ts b/backend/src/middlewares/passportStrategyMiddleware.ts index 7facd90bfe..0c5072414c 100644 --- a/backend/src/middlewares/passportStrategyMiddleware.ts +++ b/backend/src/middlewares/passportStrategyMiddleware.ts @@ -1,9 +1,9 @@ import { getServiceLogger } from '@crowd/logging' -import { TWITTER_CONFIG, SLACK_CONFIG, GOOGLE_CONFIG, GITHUB_CONFIG } from '../conf' -import { getTwitterStrategy } from '../services/auth/passportStrategies/twitterStrategy' -import { getSlackStrategy } from '../services/auth/passportStrategies/slackStrategy' +import passport from 'passport' +import { GOOGLE_CONFIG, SLACK_CONFIG, GITHUB_CONFIG} from '../conf' import { getGoogleStrategy } from '../services/auth/passportStrategies/googleStrategy' -import { getGithubStrategy } from '../services/auth/passportStrategies/githubStrategy' +import { getSlackStrategy } from '../services/auth/passportStrategies/slackStrategy' +import { getGithubStrategy } from '@/services/auth/passportStrategies/githubStrategy' const log = getServiceLogger() @@ -29,4 +29,4 @@ export async function passportStrategyMiddleware(req, res, next) { } finally { next() } -} +} \ No newline at end of file diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index 458fea765b..3d2e8507f0 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -17,7 +17,6 @@ export function getGithubStrategy(): GithubStrategy { (accessToken, refreshToken, profile, done) => { databaseInit() .then((database) => { - console.log('profile', profile) const email = get(profile, 'emails[0].value') const displayName = get(profile, 'displayName') const { firstName, lastName } = splitFullName(displayName) @@ -44,20 +43,19 @@ export function getGithubStrategy(): GithubStrategy { ) } - // TODO: This is duplicated in googleStrategy.ts and should be moved to a common place function splitFullName(fullName) { - let firstName - let lastName - - if (fullName && fullName.split(' ').length > 1) { - const [firstNameArray, ...lastNameArray] = fullName.split(' ') - firstName = firstNameArray - lastName = lastNameArray.join(' ') - } else { - firstName = fullName || null - lastName = null - } - - return { firstName, lastName } + let firstName + let lastName + + if (fullName && fullName.split(' ').length > 1) { + const [firstNameArray, ...lastNameArray] = fullName.split(' ') + firstName = firstNameArray + lastName = lastNameArray.join(' ') + } else { + firstName = fullName || null + lastName = null } + + return { firstName, lastName } +} From 43c220256f025155f02eba98a53515f8ec563f0e Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Fri, 7 Jul 2023 17:53:48 +0530 Subject: [PATCH 04/10] fix import and prettify the code --- backend/src/middlewares/passportStrategyMiddleware.ts | 6 +++--- .../src/services/auth/passportStrategies/googleStrategy.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/middlewares/passportStrategyMiddleware.ts b/backend/src/middlewares/passportStrategyMiddleware.ts index 0c5072414c..3df0fd792f 100644 --- a/backend/src/middlewares/passportStrategyMiddleware.ts +++ b/backend/src/middlewares/passportStrategyMiddleware.ts @@ -1,9 +1,9 @@ import { getServiceLogger } from '@crowd/logging' import passport from 'passport' -import { GOOGLE_CONFIG, SLACK_CONFIG, GITHUB_CONFIG} from '../conf' +import { GOOGLE_CONFIG, SLACK_CONFIG, GITHUB_CONFIG } from '../conf' import { getGoogleStrategy } from '../services/auth/passportStrategies/googleStrategy' import { getSlackStrategy } from '../services/auth/passportStrategies/slackStrategy' -import { getGithubStrategy } from '@/services/auth/passportStrategies/githubStrategy' +import { getGithubStrategy } from '../services/auth/passportStrategies/githubStrategy' const log = getServiceLogger() @@ -29,4 +29,4 @@ export async function passportStrategyMiddleware(req, res, next) { } finally { next() } -} \ No newline at end of file +} diff --git a/backend/src/services/auth/passportStrategies/googleStrategy.ts b/backend/src/services/auth/passportStrategies/googleStrategy.ts index dd63dc4b59..38ac46b6b7 100644 --- a/backend/src/services/auth/passportStrategies/googleStrategy.ts +++ b/backend/src/services/auth/passportStrategies/googleStrategy.ts @@ -58,4 +58,4 @@ function splitFullName(fullName) { } return { firstName, lastName } -} \ No newline at end of file +} From cbded40fb2f4f090e28321c49be39105cab00d5d Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Fri, 7 Jul 2023 18:24:24 +0530 Subject: [PATCH 05/10] revert: user scopes and emailVerified --- backend/src/api/auth/authSocial.ts | 2 +- .../src/services/auth/passportStrategies/githubStrategy.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/src/api/auth/authSocial.ts b/backend/src/api/auth/authSocial.ts index 76d9fc34d2..97d9b29f0f 100644 --- a/backend/src/api/auth/authSocial.ts +++ b/backend/src/api/auth/authSocial.ts @@ -51,7 +51,7 @@ export default (app, routes) => { routes.get( '/auth/social/github', passport.authenticate('github', { - scope: ['user:email'], + scope: ['user:email', 'read:user'], session: false, }), () => { diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index 3d2e8507f0..1d404aa8f3 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -13,11 +13,13 @@ export function getGithubStrategy(): GithubStrategy { clientID: GITHUB_CONFIG.clientId, clientSecret: GITHUB_CONFIG.clientSecret, callbackURL: GITHUB_CONFIG.callbackUrl, + scope: ['user:email'] // Request email scope }, (accessToken, refreshToken, profile, done) => { databaseInit() .then((database) => { const email = get(profile, 'emails[0].value') + const emailVerified = get(profile, 'emails[0].verified', false) const displayName = get(profile, 'displayName') const { firstName, lastName } = splitFullName(displayName) @@ -25,7 +27,7 @@ export function getGithubStrategy(): GithubStrategy { 'github', profile.id, email, - true, // Github does not provide email verification in profile + emailVerified, firstName, lastName, displayName, From 60f5f9281a27967a7954434b2e11ebabbeec3d3f Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Fri, 7 Jul 2023 23:34:54 +0530 Subject: [PATCH 06/10] fix eslint erros and run prettier --- backend/src/services/auth/passportStrategies/githubStrategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index 1d404aa8f3..5ecc32f90f 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -13,7 +13,7 @@ export function getGithubStrategy(): GithubStrategy { clientID: GITHUB_CONFIG.clientId, clientSecret: GITHUB_CONFIG.clientSecret, callbackURL: GITHUB_CONFIG.callbackUrl, - scope: ['user:email'] // Request email scope + scope: ['user:email'], // Request email scope }, (accessToken, refreshToken, profile, done) => { databaseInit() From c7ae75b1974e4347be02c862e3e0fabb23a8392a Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Mon, 10 Jul 2023 17:52:44 +0530 Subject: [PATCH 07/10] add code structure improvements --- .../auth/passportStrategies/githubStrategy.ts | 23 ++++-------------- .../auth/passportStrategies/googleStrategy.ts | 24 ++++--------------- backend/src/types/common.ts | 5 ++++ backend/src/utils/splitName.ts | 16 +++++++++++++ 4 files changed, 30 insertions(+), 38 deletions(-) create mode 100644 backend/src/utils/splitName.ts diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index 5ecc32f90f..20c7645e63 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -4,6 +4,8 @@ import { getServiceChildLogger } from '@crowd/logging' import { GITHUB_CONFIG } from '../../../conf' import { databaseInit } from '../../../database/databaseConnection' import AuthService from '../authService' +import { splitFullName } from '../../../utils/splitName' +import { AuthProvider } from '../../../types/common' const log = getServiceChildLogger('AuthSocial') @@ -24,7 +26,7 @@ export function getGithubStrategy(): GithubStrategy { const { firstName, lastName } = splitFullName(displayName) return AuthService.signinFromSocial( - 'github', + AuthProvider.GITHUB, profile.id, email, emailVerified, @@ -43,21 +45,4 @@ export function getGithubStrategy(): GithubStrategy { }) }, ) -} - -// TODO: This is duplicated in googleStrategy.ts and should be moved to a common place -function splitFullName(fullName) { - let firstName - let lastName - - if (fullName && fullName.split(' ').length > 1) { - const [firstNameArray, ...lastNameArray] = fullName.split(' ') - firstName = firstNameArray - lastName = lastNameArray.join(' ') - } else { - firstName = fullName || null - lastName = null - } - - return { firstName, lastName } -} +} \ No newline at end of file diff --git a/backend/src/services/auth/passportStrategies/googleStrategy.ts b/backend/src/services/auth/passportStrategies/googleStrategy.ts index 38ac46b6b7..50c21c90f4 100644 --- a/backend/src/services/auth/passportStrategies/googleStrategy.ts +++ b/backend/src/services/auth/passportStrategies/googleStrategy.ts @@ -4,6 +4,8 @@ import { getServiceChildLogger } from '@crowd/logging' import { GOOGLE_CONFIG } from '../../../conf' import { databaseInit } from '../../../database/databaseConnection' import AuthService from '../authService' +import { splitFullName } from '../../../utils/splitName' +import { AuthProvider } from '../../../types/common' const log = getServiceChildLogger('AuthSocial') @@ -11,7 +13,7 @@ export function getGoogleStrategy(): GoogleStrategy { return new GoogleStrategy( { clientID: GOOGLE_CONFIG.clientId, - clientSecret: GOOGLE_CONFIG.clientSecret, + clientSecret: GOOGLE_CONFIG.clientSecret, callbackURL: GOOGLE_CONFIG.callbackUrl, }, (accessToken, refreshToken, profile, done) => { @@ -23,7 +25,7 @@ export function getGoogleStrategy(): GoogleStrategy { const { firstName, lastName } = splitFullName(displayName) return AuthService.signinFromSocial( - 'google', + AuthProvider.GOOGLE, profile.id, email, emailVerified, @@ -42,20 +44,4 @@ export function getGoogleStrategy(): GoogleStrategy { }) }, ) -} - -function splitFullName(fullName) { - let firstName - let lastName - - if (fullName && fullName.split(' ').length > 1) { - const [firstNameArray, ...lastNameArray] = fullName.split(' ') - firstName = firstNameArray - lastName = lastNameArray.join(' ') - } else { - firstName = fullName || null - lastName = null - } - - return { firstName, lastName } -} +} \ No newline at end of file diff --git a/backend/src/types/common.ts b/backend/src/types/common.ts index c78f57c281..df2d093a4c 100644 --- a/backend/src/types/common.ts +++ b/backend/src/types/common.ts @@ -33,3 +33,8 @@ export enum FeatureFlagRedisKey { MEMBER_ENRICHMENT_COUNT = 'memberEnrichmentCount', ORGANIZATION_ENRICHMENT_COUNT = 'organizationEnrichmentCount', } + +export enum AuthProvider { + GOOGLE = 'google', + GITHUB = 'github', +} \ No newline at end of file diff --git a/backend/src/utils/splitName.ts b/backend/src/utils/splitName.ts new file mode 100644 index 0000000000..226ff1ea29 --- /dev/null +++ b/backend/src/utils/splitName.ts @@ -0,0 +1,16 @@ +export function splitFullName(fullName) { + let firstName + let lastName + + if (fullName && fullName.split(' ').length > 1) { + const [firstNameArray, ...lastNameArray] = fullName.split(' ') + firstName = firstNameArray + lastName = lastNameArray.join(' ') + } else { + firstName = fullName || null + lastName = null + } + + return { firstName, lastName } + } + \ No newline at end of file From 195e3bbc5b1ee2187546bb3f2f159bd5b3a855cf Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Mon, 10 Jul 2023 18:08:35 +0530 Subject: [PATCH 08/10] prettify the code and add remix icon for the github logo --- .../auth/passportStrategies/githubStrategy.ts | 2 +- .../auth/passportStrategies/googleStrategy.ts | 4 +-- backend/src/types/common.ts | 2 +- backend/src/utils/splitName.ts | 27 +++++++++---------- .../src/modules/auth/pages/signin-page.vue | 4 +-- .../src/modules/auth/pages/signup-page.vue | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index 20c7645e63..badb5c6248 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -45,4 +45,4 @@ export function getGithubStrategy(): GithubStrategy { }) }, ) -} \ No newline at end of file +} diff --git a/backend/src/services/auth/passportStrategies/googleStrategy.ts b/backend/src/services/auth/passportStrategies/googleStrategy.ts index 50c21c90f4..1b9e6636f6 100644 --- a/backend/src/services/auth/passportStrategies/googleStrategy.ts +++ b/backend/src/services/auth/passportStrategies/googleStrategy.ts @@ -13,7 +13,7 @@ export function getGoogleStrategy(): GoogleStrategy { return new GoogleStrategy( { clientID: GOOGLE_CONFIG.clientId, - clientSecret: GOOGLE_CONFIG.clientSecret, + clientSecret: GOOGLE_CONFIG.clientSecret, callbackURL: GOOGLE_CONFIG.callbackUrl, }, (accessToken, refreshToken, profile, done) => { @@ -44,4 +44,4 @@ export function getGoogleStrategy(): GoogleStrategy { }) }, ) -} \ No newline at end of file +} diff --git a/backend/src/types/common.ts b/backend/src/types/common.ts index df2d093a4c..a88a4c5a57 100644 --- a/backend/src/types/common.ts +++ b/backend/src/types/common.ts @@ -37,4 +37,4 @@ export enum FeatureFlagRedisKey { export enum AuthProvider { GOOGLE = 'google', GITHUB = 'github', -} \ No newline at end of file +} diff --git a/backend/src/utils/splitName.ts b/backend/src/utils/splitName.ts index 226ff1ea29..809ac1a13c 100644 --- a/backend/src/utils/splitName.ts +++ b/backend/src/utils/splitName.ts @@ -1,16 +1,15 @@ export function splitFullName(fullName) { - let firstName - let lastName - - if (fullName && fullName.split(' ').length > 1) { - const [firstNameArray, ...lastNameArray] = fullName.split(' ') - firstName = firstNameArray - lastName = lastNameArray.join(' ') - } else { - firstName = fullName || null - lastName = null - } - - return { firstName, lastName } + let firstName + let lastName + + if (fullName && fullName.split(' ').length > 1) { + const [firstNameArray, ...lastNameArray] = fullName.split(' ') + firstName = firstNameArray + lastName = lastNameArray.join(' ') + } else { + firstName = fullName || null + lastName = null } - \ No newline at end of file + + return { firstName, lastName } +} diff --git a/frontend/src/modules/auth/pages/signin-page.vue b/frontend/src/modules/auth/pages/signin-page.vue index ebafd888fc..bb4bfac6c9 100644 --- a/frontend/src/modules/auth/pages/signin-page.vue +++ b/frontend/src/modules/auth/pages/signin-page.vue @@ -131,8 +131,8 @@ :href="socialOauthLink('github')" class="btn btn--secondary btn--lg w-full" > - - Sign in with GitHub + + Sign in with GitHub

diff --git a/frontend/src/modules/auth/pages/signup-page.vue b/frontend/src/modules/auth/pages/signup-page.vue index 50b22ab194..c02da342ef 100644 --- a/frontend/src/modules/auth/pages/signup-page.vue +++ b/frontend/src/modules/auth/pages/signup-page.vue @@ -208,7 +208,7 @@ :href="socialOauthLink('github')" class="btn btn--secondary btn--lg w-full" > - + Sign up with GitHub
From 067b2667d980c897a244a4cbed5a7646e5834096 Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Mon, 10 Jul 2023 20:33:07 +0530 Subject: [PATCH 09/10] remove emailVerified field from profile and introduce gh callbackURL env var --- backend/config/custom-environment-variables.json | 1 + .../src/services/auth/passportStrategies/githubStrategy.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/config/custom-environment-variables.json b/backend/config/custom-environment-variables.json index 509f4f312b..7fe50e8789 100644 --- a/backend/config/custom-environment-variables.json +++ b/backend/config/custom-environment-variables.json @@ -129,6 +129,7 @@ "appId": "CROWD_GITHUB_APP_ID", "clientId": "CROWD_GITHUB_CLIENT_ID", "clientSecret": "CROWD_GITHUB_CLIENT_SECRET", + "callbackUrl": "CROWD_GITHUB_CALLBACK_URL", "privateKey": "CROWD_GITHUB_PRIVATE_KEY", "webhookSecret": "CROWD_GITHUB_WEBHOOK_SECRET", "isCommitDataEnabled": "CROWD_GITHUB_IS_COMMIT_DATA_ENABLED" diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index badb5c6248..c4dac1cfcd 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -21,7 +21,9 @@ export function getGithubStrategy(): GithubStrategy { databaseInit() .then((database) => { const email = get(profile, 'emails[0].value') - const emailVerified = get(profile, 'emails[0].verified', false) + // GitHub user's profile doesn't include 'verified' field + // However, GitHub accounts require email verification for activation + const emailVerified = email ? true : false const displayName = get(profile, 'displayName') const { firstName, lastName } = splitFullName(displayName) From d2840091b829ea18e77427428e4e17f430955b52 Mon Sep 17 00:00:00 2001 From: Yeganathan S Date: Mon, 10 Jul 2023 20:46:48 +0530 Subject: [PATCH 10/10] fix eslint issue --- backend/src/services/auth/passportStrategies/githubStrategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/services/auth/passportStrategies/githubStrategy.ts b/backend/src/services/auth/passportStrategies/githubStrategy.ts index c4dac1cfcd..bfb2576c00 100644 --- a/backend/src/services/auth/passportStrategies/githubStrategy.ts +++ b/backend/src/services/auth/passportStrategies/githubStrategy.ts @@ -23,7 +23,7 @@ export function getGithubStrategy(): GithubStrategy { const email = get(profile, 'emails[0].value') // GitHub user's profile doesn't include 'verified' field // However, GitHub accounts require email verification for activation - const emailVerified = email ? true : false + const emailVerified = !!email const displayName = get(profile, 'displayName') const { firstName, lastName } = splitFullName(displayName)