Skip to content

Commit 64eaace

Browse files
epipavUroš Marolt
andauthored
Oauth2 PKCE state using redis (#236)
Co-authored-by: Uroš Marolt <[email protected]>
1 parent 65c0964 commit 64eaace

29 files changed

+3081
-231
lines changed

backend/.env.dist.composed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ CROWD_SQS_NODEJS_WORKER_DELAYABLE_QUEUE=http://sqs:9324/000000000000/nodejs-work
99
CROWD_SQS_PYTHON_WORKER_QUEUE="http://sqs:9324/000000000000/python-worker.fifo"
1010
CROWD_SQS_PREMIUM_PYTHON_WORKER_QUEUE="http://sqs:9324/000000000000/premium-python-worker.fifo"
1111

12+
# Redis settings
13+
CROWD_REDIS_HOST=redis
14+
1215
# S3 settings
1316
CROWD_S3_HOST="s3"
1417

backend/.env.dist.local

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ CROWD_SQS_AWS_ACCESS_KEY_ID=x
2424
CROWD_SQS_AWS_SECRET_ACCESS_KEY=x
2525
CROWD_SQS_AWS_REGION=elasticmq
2626

27+
# Redis settings
28+
CROWD_REDIS_USERNAME=default
29+
CROWD_REDIS_PASSWORD=crowdtest
30+
CROWD_REDIS_HOST=localhost
31+
CROWD_REDIS_PORT=6379
32+
2733
# S3 settings
2834
CROWD_S3_HOST=localhost
2935
CROWD_S3_PORT=9000

backend/config/custom-environment-variables.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"jwtExpiresIn": "CROWD_API_JWT_EXPIRES_IN",
99
"premiumApiUrl": "CROWD_PREMIUM_API_URL"
1010
},
11+
"redis": {
12+
"username": "CROWD_REDIS_USERNAME",
13+
"password": "CROWD_REDIS_PASSWORD",
14+
"host": "CROWD_REDIS_HOST",
15+
"port": "CROWD_REDIS_PORT"
16+
},
1117
"sqs": {
1218
"host": "CROWD_SQS_HOST",
1319
"port": "CROWD_SQS_PORT",

backend/package-lock.json

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"scripts": {
55
"start:api": "ts-node --transpile-only ./src/bin/api.ts",
66
"start:api:dev": "nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/api.ts\"",
7-
"start:api:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=api nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/api.ts\"",
7+
"start:api:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=api nodemon --signal SIGKILL --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/api.ts\"",
88
"start:job-generator": "ts-node --transpile-only ./src/bin/job-generator.ts",
99
"start:job-generator:dev": "nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/job-generator.ts\"",
10-
"start:job-generator:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=job-generator nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/job-generator.ts\"",
10+
"start:job-generator:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=job-generator nodemon --signal SIGKILL --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/job-generator.ts\"",
1111
"start:nodejs-worker": "ts-node --transpile-only ./src/bin/nodejs-worker.ts",
1212
"start:nodejs-worker:dev": "nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"ts-node --transpile-only ./src/bin/nodejs-worker.ts\"",
13-
"start:nodejs-worker:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=nodejs-worker nodemon --watch \"src/**/*.ts\" -e ts,json --exec \"node --inspect=0.0.0.0:9229 -r ts-node/register ./src/bin/nodejs-worker.ts --transpile-only\"",
13+
"start:nodejs-worker:dev:local": "set -a && . ./.env.dist.local && . ./.env.override.local && set +a && SERVICE=nodejs-worker nodemon --signal SIGKILL --watch \"src/**/*.ts\" -e ts,json --exec \"node --inspect=0.0.0.0:9229 -r ts-node/register ./src/bin/nodejs-worker.ts --transpile-only\"",
1414
"build": "tsc && npm run build:documentation && cp package*json dist/ && cp .sequelizerc dist/.sequelizerc ",
1515
"test": "../scripts/cli scaffold up-test && jest --clearCache && set -a && . ./.env.dist.local && . ./.env.test && set +a && NODE_ENV=test SERVICE=test jest --runInBand --verbose --forceExit",
1616
"build:documentation": "copyfiles --flat ./src/documentation/openapi.json ./dist/documentation/",
@@ -77,6 +77,7 @@
7777
"passport-slack": "0.0.7",
7878
"pg": "^8.7.3",
7979
"pm2": "^5.2.0",
80+
"redis": "^4.5.0",
8081
"sanitize-html": "^2.7.1",
8182
"sequelize": "6.21.2",
8283
"sequelize-cli-typescript": "^3.2.0-c",

backend/src/api/auth/authSocial.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { get } from 'lodash'
21
import passport from 'passport'
3-
import GoogleStrategy from 'passport-google-oauth20'
42
import { API_CONFIG, GOOGLE_CONFIG } from '../../config'
5-
import { databaseInit } from '../../database/databaseConnection'
63
import AuthService from '../../services/auth/authService'
74
import { createServiceChildLogger } from '../../utils/logging'
85

@@ -31,43 +28,6 @@ export default (app, routes) => {
3128
})
3229

3330
if (GOOGLE_CONFIG.clientId) {
34-
passport.use(
35-
new GoogleStrategy(
36-
{
37-
clientID: GOOGLE_CONFIG.clientId,
38-
clientSecret: GOOGLE_CONFIG.clientSecret,
39-
callbackURL: GOOGLE_CONFIG.callbackUrl,
40-
},
41-
(accessToken, refreshToken, profile, done) => {
42-
databaseInit()
43-
.then((database) => {
44-
const email = get(profile, 'emails[0].value')
45-
const emailVerified = get(profile, 'emails[0].verified', false)
46-
const displayName = get(profile, 'displayName')
47-
const { firstName, lastName } = splitFullName(displayName)
48-
49-
return AuthService.signinFromSocial(
50-
'google',
51-
profile.id,
52-
email,
53-
emailVerified,
54-
firstName,
55-
lastName,
56-
displayName,
57-
{ database },
58-
)
59-
})
60-
.then((jwtToken) => {
61-
done(null, jwtToken)
62-
})
63-
.catch((error) => {
64-
log.error(error, 'Error while handling google auth!')
65-
done(error, null)
66-
})
67-
},
68-
),
69-
)
70-
7131
routes.get(
7232
'/auth/social/google',
7333
passport.authenticate('google', {
@@ -103,19 +63,3 @@ function handleCallback(res, err, jwtToken) {
10363

10464
res.redirect(`${API_CONFIG.frontendUrl}/?social=true&authToken=${jwtToken}`)
10565
}
106-
107-
function splitFullName(fullName) {
108-
let firstName
109-
let lastName
110-
111-
if (fullName && fullName.split(' ').length > 1) {
112-
const [firstNameArray, ...lastNameArray] = fullName.split(' ')
113-
firstName = firstNameArray
114-
lastName = lastNameArray.join(' ')
115-
} else {
116-
firstName = fullName || null
117-
lastName = null
118-
}
119-
120-
return { firstName, lastName }
121-
}

0 commit comments

Comments
 (0)