Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/meteor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
"passport-github2": "^0.1.12",
"passport-google-oauth20": "^2.0.0",
"passport-oauth2": "^1.8.0",
"passport-twitter": "^1.0.4",
"path": "^0.12.7",
"path-to-regexp": "^6.3.0",
"pino": "10.3.1",
Expand Down Expand Up @@ -400,6 +401,7 @@
"@types/passport-github2": "^1.2.9",
"@types/passport-google-oauth20": "^2",
"@types/passport-oauth2": "^1",
"@types/passport-twitter": "^1",
"@types/prometheus-gc-stats": "^0.6.4",
"@types/proxy-from-env": "^1.0.4",
"@types/proxyquire": "^1.3.31",
Expand Down
2 changes: 2 additions & 0 deletions apps/meteor/server/lib/oauth/configureOAuthServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const configureOAuthServices = (oauthServiceConfig: OAuthServiceConfig[],
...config,
clientID: config.clientId,
clientSecret: config.clientSecret,
consumerKey: config.clientId,
consumerSecret: config.clientSecret,
callbackURL: `${siteUrl}/oauth/${config.provider}/callback`,
state: true,
pkce: true,
Expand Down
46 changes: 26 additions & 20 deletions apps/meteor/server/lib/oauth/createOAuthServiceConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { capitalize } from '@rocket.chat/string-helpers';
import { isTruthy } from '@rocket.chat/tools';
import type { Strategy } from 'passport';

import { OAuthConfigs } from './oauthConfigs';
Expand All @@ -9,30 +10,35 @@ export type OAuthServiceConfig = {
strategy: new (...args: any[]) => Strategy;
clientId: string;
clientSecret: string;
scope: string[];
scope?: string[];
};

export const createOAuthServiceConfig = (settings: ICachedSettings, services: string[]): OAuthServiceConfig[] => {
return services.map((service) => {
if (service === 'github_enterprise') {
return services
.map((service) => {
if (!OAuthConfigs[service]) {
return;
}

if (service === 'github_enterprise') {
return {
provider: service,
clientId: settings.get<string>('Accounts_OAuth_GitHub_Enterprise_id'),
clientSecret: settings.get<string>('Accounts_OAuth_GitHub_Enterprise_secret'),
authorizationURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/login/oauth/authorize`,
tokenURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/login/oauth/access_token`,
userProfileURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/api/v3/user`,
strategy: OAuthConfigs.github_enterprise.strategy,
scope: OAuthConfigs.github_enterprise.scope,
};
}

return {
provider: service,
clientId: settings.get<string>('Accounts_OAuth_GitHub_Enterprise_id'),
clientSecret: settings.get<string>('Accounts_OAuth_GitHub_Enterprise_secret'),
authorizationURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/login/oauth/authorize`,
tokenURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/login/oauth/access_token`,
userProfileURL: `${settings.get<string>('API_GitHub_Enterprise_URL')}/api/v3/user`,
strategy: OAuthConfigs.github_enterprise.strategy,
scope: OAuthConfigs.github_enterprise.scope,
clientId: settings.get<string>(`Accounts_OAuth_${capitalize(service)}_id`),
clientSecret: settings.get<string>(`Accounts_OAuth_${capitalize(service)}_secret`),
...OAuthConfigs[service],
};
}

return {
provider: service,
strategy: OAuthConfigs[service].strategy,
clientId: settings.get<string>(`Accounts_OAuth_${capitalize(service)}_id`),
clientSecret: settings.get<string>(`Accounts_OAuth_${capitalize(service)}_secret`),
scope: OAuthConfigs[service].scope,
};
});
})
.filter(isTruthy);
};
8 changes: 7 additions & 1 deletion apps/meteor/server/lib/oauth/oauthConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import type { Strategy } from 'passport';
import { Strategy as FacebookStrategy } from 'passport-facebook';
import { Strategy as GitHubStrategy } from 'passport-github2';
import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
import { Strategy as TwitterStrategy } from 'passport-twitter';

export type OAuthConfig = {
strategy: new (...args: any[]) => Strategy;
scope: string[];
scope?: string[];
includeEmail?: boolean;
};

export const OAuthConfigs: Record<string, OAuthConfig> = {
Expand All @@ -21,6 +23,10 @@ export const OAuthConfigs: Record<string, OAuthConfig> = {
strategy: GoogleStrategy,
scope: ['email', 'profile'],
},
twitter: {
strategy: TwitterStrategy,
includeEmail: true,
Comment thread
yash-rajpal marked this conversation as resolved.
},
github_enterprise: {
strategy: GitHubStrategy,
scope: ['user:email'],
Expand Down
56 changes: 56 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9850,6 +9850,7 @@ __metadata:
"@types/passport-github2": "npm:^1.2.9"
"@types/passport-google-oauth20": "npm:^2"
"@types/passport-oauth2": "npm:^1"
"@types/passport-twitter": "npm:^1"
"@types/prometheus-gc-stats": "npm:^0.6.4"
"@types/proxy-from-env": "npm:^1.0.4"
"@types/proxyquire": "npm:^1.3.31"
Expand Down Expand Up @@ -9996,6 +9997,7 @@ __metadata:
passport-github2: "npm:^0.1.12"
passport-google-oauth20: "npm:^2.0.0"
passport-oauth2: "npm:^1.8.0"
passport-twitter: "npm:^1.0.4"
path: "npm:^0.12.7"
path-to-regexp: "npm:^6.3.0"
pino: "npm:10.3.1"
Expand Down Expand Up @@ -14786,6 +14788,16 @@ __metadata:
languageName: node
linkType: hard

"@types/passport-twitter@npm:^1":
version: 1.0.40
resolution: "@types/passport-twitter@npm:1.0.40"
dependencies:
"@types/express": "npm:*"
"@types/passport": "npm:*"
checksum: 10/cf97db9469acff4dffff11ecf4e12ac016fc55d478e2fbd881c7961fe36f26ba232a55f74fdd0bd0216ea49d3a9dcd4e18afac852b6bb10450f43413e4a464b7
languageName: node
linkType: hard

"@types/passport@npm:*, @types/passport@npm:^1.0.17":
version: 1.0.17
resolution: "@types/passport@npm:1.0.17"
Expand Down Expand Up @@ -29320,6 +29332,13 @@ __metadata:
languageName: node
linkType: hard

"oauth@npm:0.9.x":
version: 0.9.15
resolution: "oauth@npm:0.9.15"
checksum: 10/6b0b10be19a461da417a37ea2821a773ef74dd667563291e1e83b2024b88e6571b0323a0a6887f2390fbaf28cc6ce5bfe0484fc22162b975305b1e19b76f5597
languageName: node
linkType: hard

"object-assign@npm:^4, object-assign@npm:^4.0.1, object-assign@npm:^4.1.1":
version: 4.1.1
resolution: "object-assign@npm:4.1.1"
Expand Down Expand Up @@ -30030,6 +30049,17 @@ __metadata:
languageName: node
linkType: hard

"passport-oauth1@npm:1.x.x":
version: 1.3.0
resolution: "passport-oauth1@npm:1.3.0"
dependencies:
oauth: "npm:0.9.x"
passport-strategy: "npm:1.x.x"
utils-merge: "npm:1.x.x"
checksum: 10/56f725cf3e3358ccb72212a6342e237ae9366172b94fdb9ac8ab380456da07dc1bb776bcdcddc9964e8e9056922fbf31c2f142d0421fd8a5b0140132d0cd9671
languageName: node
linkType: hard

"passport-oauth2@npm:1.x.x, passport-oauth2@npm:^1.8.0":
version: 1.8.0
resolution: "passport-oauth2@npm:1.8.0"
Expand All @@ -30050,6 +30080,16 @@ __metadata:
languageName: node
linkType: hard

"passport-twitter@npm:^1.0.4":
version: 1.0.4
resolution: "passport-twitter@npm:1.0.4"
dependencies:
passport-oauth1: "npm:1.x.x"
xtraverse: "npm:0.1.x"
checksum: 10/46c2efcbd8893c2de329770f16703b027531e2becfc8865dd288290635dcc9a678bbcec82a66ad52e49742bccd77ff4fc49f576fef2d711f49363e1b75ac1e80
languageName: node
linkType: hard

"passport@npm:^0.7.0":
version: 0.7.0
resolution: "passport@npm:0.7.0"
Expand Down Expand Up @@ -37866,6 +37906,13 @@ __metadata:
languageName: node
linkType: hard

"xmldom@npm:0.1.x":
version: 0.1.31
resolution: "xmldom@npm:0.1.31"
checksum: 10/eddc09391c928be61c504a355d5b7c42cbec526e94cc1e2d092d006ed5bc1525b869fb922cbcf3f6f7aac946a6b25ec4243dc2630afb5cbec61b723829211792
languageName: node
linkType: hard

"xorshift@npm:^1.1.1":
version: 1.2.0
resolution: "xorshift@npm:1.2.0"
Expand Down Expand Up @@ -37901,6 +37948,15 @@ __metadata:
languageName: node
linkType: hard

"xtraverse@npm:0.1.x":
version: 0.1.0
resolution: "xtraverse@npm:0.1.0"
dependencies:
xmldom: "npm:0.1.x"
checksum: 10/86e837a626ef363c01efa55a3e20b1d85b49d87f3de504955af119b451cb1f2c63e887bff6061335314c1d49005d851f4bc1d0cf2603dce18271aceb3e673d8a
languageName: node
linkType: hard

"xxhashjs@npm:~0.2.2":
version: 0.2.2
resolution: "xxhashjs@npm:0.2.2"
Expand Down
Loading