Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into improvement/clean-up-…
Browse files Browse the repository at this point in the history
…filters-code
  • Loading branch information
joanagmaia committed Jul 13, 2023
2 parents b2c8da2 + 8b2f03f commit 7cdf093
Show file tree
Hide file tree
Showing 97 changed files with 2,371 additions and 993 deletions.
4 changes: 2 additions & 2 deletions backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -180,8 +181,7 @@
"secretAccessKey": "CROWD_OPENSEARCH_AWS_SECRET_ACCESS_KEY"
},
"auth0": {
"domain": "CROWD_AUTH0_DOMAIN",
"clientId": "CROWD_AUTH0_CLIENT_ID",
"cert": "CROWD_AUTH0_CERT"
"jwks": "CROWD_AUTH0_JWKS"
}
}
133 changes: 133 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"html-to-text": "^8.2.1",
"json2csv": "^5.0.7",
"jsonwebtoken": "8.5.1",
"jwks-rsa": "^3.0.1",
"lodash": "4.17.21",
"moment": "2.29.4",
"moment-timezone": "^0.5.34",
Expand All @@ -108,6 +109,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",
Expand Down
22 changes: 21 additions & 1 deletion backend/src/api/auth/authSocial.ts
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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', 'read:user'],
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) {
Expand Down
27 changes: 20 additions & 7 deletions backend/src/api/auth/ssoCallback.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
import jwt from 'jsonwebtoken'
import jwksClient from 'jwks-rsa'
import AuthService from '../../services/auth/authService'
import { AUTH0_CONFIG } from '../../conf'
import Error401 from '../../errors/Error401'

const jwks = jwksClient({
jwksUri: AUTH0_CONFIG.jwks,
cache: true,
cacheMaxEntries: 5,
cacheMaxAge: 86400000,
})

async function getKey(header, callback) {
jwks.getSigningKey(header.kid, (err, key: any) => {
const signingKey = key.publicKey || key.rsaPublicKey
callback(null, signingKey)
})
}

export default async (req, res) => {
const { idToken, invitationToken, tenantId } = req.body

try {
const verifyToken = new Promise((resolve, reject) => {
const publicKey = AUTH0_CONFIG.cert.replaceAll('"', '').replace(/\\n/g, '\n')
jwt.verify(idToken, publicKey, { algorithms: ['RS256'] }, (err, decoded) => {
// If error verifying token
jwt.verify(idToken, getKey, { algorithms: ['RS256'] }, (err, decoded) => {
if (err) {
reject(new Error401())
}

// If token matches auth0 validation criteria
const { aud, iss } = decoded as any
if (aud !== AUTH0_CONFIG.clientId || !iss.includes(AUTH0_CONFIG.domain)) {
const { aud } = decoded as any

if (aud !== AUTH0_CONFIG.clientId) {
reject(new Error401())
}

// If token validation passed
resolve(decoded)
})
})
const data: any = await verifyToken

// Signin with data
const token: string = await AuthService.signinFromSSO(
'auth0',
Expand Down
2 changes: 1 addition & 1 deletion backend/src/api/webhooks/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async (req, res) => {

await sendNodeWorkerMessage(
integration.tenantId,
new NodeWorkerProcessWebhookMessage(integration.tenantId, result.id),
new NodeWorkerProcessWebhookMessage(integration.tenantId, result.id, undefined, true),
)

await req.responseHandler.success(req, res, {}, 204)
Expand Down
4 changes: 2 additions & 2 deletions backend/src/conf/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ export interface ApiConfiguration {
}

export interface Auth0Configuration {
domain: string
clientId: string
cert: string
jwks: string
}

export interface PlansConfiguration {
Expand Down Expand Up @@ -144,6 +143,7 @@ export interface GithubConfiguration {
webhookSecret: string
isCommitDataEnabled: string
globalLimit?: number
callbackUrl: string
}

export interface SendgridConfiguration {
Expand Down
Loading

0 comments on commit 7cdf093

Please sign in to comment.