From 0f3fc5a4d1c0e9035ebc549ba1fd31a009bc545f Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 25 Nov 2025 18:06:23 +0530 Subject: [PATCH 1/3] chore: move github OAuth to customOAuth --- apps/meteor/.meteor/packages | 1 - apps/meteor/.meteor/versions | 2 - apps/meteor/app/github/server/index.ts | 1 + apps/meteor/app/github/server/lib.ts | 19 ++++++++ apps/meteor/client/meteor/login/github.ts | 44 ------------------- apps/meteor/client/meteor/login/index.ts | 1 - apps/meteor/client/views/root/AppLayout.tsx | 2 + .../root/hooks/customOAuth/useGithubOAuth.ts | 33 ++++++++++++++ apps/meteor/server/importPackages.ts | 1 + 9 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 apps/meteor/app/github/server/index.ts create mode 100644 apps/meteor/app/github/server/lib.ts delete mode 100644 apps/meteor/client/meteor/login/github.ts create mode 100644 apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts diff --git a/apps/meteor/.meteor/packages b/apps/meteor/.meteor/packages index 0dce43f784ee4..964e8352f7a5f 100644 --- a/apps/meteor/.meteor/packages +++ b/apps/meteor/.meteor/packages @@ -11,7 +11,6 @@ rocketchat:version accounts-base@3.1.2 accounts-facebook@1.3.4 -accounts-github@1.5.1 accounts-google@1.4.1 accounts-meteor-developer@1.5.1 accounts-oauth@1.4.6 diff --git a/apps/meteor/.meteor/versions b/apps/meteor/.meteor/versions index 04d79cb550212..5a80202e4ebe0 100644 --- a/apps/meteor/.meteor/versions +++ b/apps/meteor/.meteor/versions @@ -1,6 +1,5 @@ accounts-base@3.1.2 accounts-facebook@1.3.4 -accounts-github@1.5.1 accounts-google@1.4.1 accounts-meteor-developer@1.5.1 accounts-oauth@1.4.6 @@ -35,7 +34,6 @@ facebook-oauth@1.11.6 facts-base@1.0.2 fetch@0.1.6 geojson-utils@1.0.12 -github-oauth@1.4.2 google-oauth@1.4.5 hot-code-push@1.0.5 http@3.0.0 diff --git a/apps/meteor/app/github/server/index.ts b/apps/meteor/app/github/server/index.ts new file mode 100644 index 0000000000000..cf327e4971bb2 --- /dev/null +++ b/apps/meteor/app/github/server/index.ts @@ -0,0 +1 @@ +import './lib'; diff --git a/apps/meteor/app/github/server/lib.ts b/apps/meteor/app/github/server/lib.ts new file mode 100644 index 0000000000000..abdc87419956a --- /dev/null +++ b/apps/meteor/app/github/server/lib.ts @@ -0,0 +1,19 @@ +import type { OauthConfig } from '@rocket.chat/core-typings'; + +import { CustomOAuth } from '../../custom-oauth/server/custom_oauth_server'; + +const config: OauthConfig = { + serverURL: 'https://github.com', + identityPath: 'https://api.github.com/user', + tokenPath: 'https://github.com/login/oauth/access_token', + scope: 'user:email', + mergeUsers: false, + addAutopublishFields: { + forLoggedInUser: ['services.github'], + forOtherUsers: ['services.github.username'], + }, + accessTokenParam: 'access_token', + identityTokenSentVia: 'header', +}; + +export const Github = new CustomOAuth('github', config); diff --git a/apps/meteor/client/meteor/login/github.ts b/apps/meteor/client/meteor/login/github.ts deleted file mode 100644 index 98c8fb8fea76d..0000000000000 --- a/apps/meteor/client/meteor/login/github.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Random } from '@rocket.chat/random'; -import { Accounts } from 'meteor/accounts-base'; -// eslint-disable-next-line import/no-duplicates -import { Github } from 'meteor/github-oauth'; -import { Meteor } from 'meteor/meteor'; -// eslint-disable-next-line import/no-duplicates -import { OAuth } from 'meteor/oauth'; - -import { createOAuthTotpLoginMethod } from './oauth'; -import { overrideLoginMethod } from '../../lib/2fa/overrideLoginMethod'; -import { wrapRequestCredentialFn } from '../../lib/wrapRequestCredentialFn'; - -const { loginWithGithub } = Meteor; -const loginWithGithubAndTOTP = createOAuthTotpLoginMethod(Github); -Meteor.loginWithGithub = (options, callback) => { - overrideLoginMethod(loginWithGithub, [options], callback, loginWithGithubAndTOTP); -}; - -Github.requestCredential = wrapRequestCredentialFn('github', ({ config, loginStyle, options, credentialRequestCompleteCallback }) => { - const credentialToken = Random.secret(); - const scope = options?.requestPermissions || ['user:email']; - const flatScope = scope.map(encodeURIComponent).join('+'); - - let allowSignup = ''; - if (Accounts._options?.forbidClientAccountCreation) { - allowSignup = '&allow_signup=false'; - } - - const loginUrl = - `https://github.com/login/oauth/authorize` + - `?client_id=${config.clientId}` + - `&scope=${flatScope}` + - `&redirect_uri=${OAuth._redirectUri('github', config)}` + - `&state=${OAuth._stateParam(loginStyle, credentialToken, options.redirectUrl)}${allowSignup}`; - - OAuth.launchLogin({ - loginService: 'github', - loginStyle, - loginUrl, - credentialRequestCompleteCallback, - credentialToken, - popupOptions: { width: 900, height: 450 }, - }); -}); diff --git a/apps/meteor/client/meteor/login/index.ts b/apps/meteor/client/meteor/login/index.ts index cef3570085f43..d49f3653de683 100644 --- a/apps/meteor/client/meteor/login/index.ts +++ b/apps/meteor/client/meteor/login/index.ts @@ -1,7 +1,6 @@ import './cas'; import './crowd'; import './facebook'; -import './github'; import './google'; import './ldap'; import './meteorDeveloperAccount'; diff --git a/apps/meteor/client/views/root/AppLayout.tsx b/apps/meteor/client/views/root/AppLayout.tsx index 6daac59b4f863..7e131c341cc3f 100644 --- a/apps/meteor/client/views/root/AppLayout.tsx +++ b/apps/meteor/client/views/root/AppLayout.tsx @@ -8,6 +8,7 @@ import { useDolphinOAuth } from './hooks/customOAuth/useDolphinOAuth'; import { useDrupalOAuth } from './hooks/customOAuth/useDrupalOAuth'; import { useGitHubEnterpriseOAuth } from './hooks/customOAuth/useGitHubEnterpriseOAuth'; import { useGitLabOAuth } from './hooks/customOAuth/useGitLabOAuth'; +import { useGithubOAuth } from './hooks/customOAuth/useGithubOAuth'; import { useNextcloudOAuth } from './hooks/customOAuth/useNextcloudOAuth'; import { useTokenpassOAuth } from './hooks/customOAuth/useTokenpassOAuth'; import { useWordPressOAuth } from './hooks/customOAuth/useWordPressOAuth'; @@ -55,6 +56,7 @@ const AppLayout = () => { useLivechatEnterprise(); useNextcloudOAuth(); useGitLabOAuth(); + useGithubOAuth(); useGitHubEnterpriseOAuth(); useDrupalOAuth(); useDolphinOAuth(); diff --git a/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts new file mode 100644 index 0000000000000..acf799e27344f --- /dev/null +++ b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts @@ -0,0 +1,33 @@ +import type { OauthConfig } from '@rocket.chat/core-typings'; +import { useSetting } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; + +import { CustomOAuth } from '../../../../lib/customOAuth/CustomOAuth'; + +const config: OauthConfig = { + authorizePath: 'https://github.com/login/oauth/authorize', + serverURL: 'https://github.com', + identityPath: 'https://api.github.com/user', + tokenPath: 'https://github.com/login/oauth/access_token', + scope: 'user:email', + mergeUsers: false, + addAutopublishFields: { + forLoggedInUser: ['services.github'], + forOtherUsers: ['services.github.username'], + }, + accessTokenParam: 'access_token', +} as const satisfies OauthConfig; + +const Github = CustomOAuth.configureOAuthService('github', config); + +export const useGithubOAuth = () => { + const enabled = useSetting('Accounts_OAuth_Github'); + + useEffect(() => { + if (enabled) { + Github.configure({ + ...config, + }); + } + }, [enabled]); +}; diff --git a/apps/meteor/server/importPackages.ts b/apps/meteor/server/importPackages.ts index e36807bf7959a..bf355b97eaf54 100644 --- a/apps/meteor/server/importPackages.ts +++ b/apps/meteor/server/importPackages.ts @@ -83,3 +83,4 @@ import '../app/reactions/server'; import '../app/livechat/server'; import '../app/authentication/server'; import '../app/voip/server/startup'; +import '../app/github/server'; From 16dcbccfdb20215e5acb8c82d37d648b7979164a Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 20 Jan 2026 21:51:22 +0530 Subject: [PATCH 2/3] refactor --- .../client/views/root/hooks/customOAuth/useGithubOAuth.ts | 6 ++++-- apps/meteor/definition/externals/meteor/github-oauth.d.ts | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-) delete mode 100644 apps/meteor/definition/externals/meteor/github-oauth.d.ts diff --git a/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts index acf799e27344f..e0c3ec6ea89eb 100644 --- a/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts +++ b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts @@ -22,12 +22,14 @@ const Github = CustomOAuth.configureOAuthService('github', config); export const useGithubOAuth = () => { const enabled = useSetting('Accounts_OAuth_Github'); + const githubApiUrl = useSetting('API_GitHub_URL', ''); useEffect(() => { - if (enabled) { + if (enabled && githubApiUrl) { Github.configure({ ...config, + serverURL: githubApiUrl, }); } - }, [enabled]); + }, [enabled, githubApiUrl]); }; diff --git a/apps/meteor/definition/externals/meteor/github-oauth.d.ts b/apps/meteor/definition/externals/meteor/github-oauth.d.ts deleted file mode 100644 index ac67405bd4e4c..0000000000000 --- a/apps/meteor/definition/externals/meteor/github-oauth.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare module 'meteor/github-oauth' { - export const Github: any; -} From 98e440fd15e061b17008e22d2c1fcd13387c54b3 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 20 Jan 2026 21:59:20 +0530 Subject: [PATCH 3/3] refactor --- .../client/views/root/hooks/customOAuth/useGithubOAuth.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts index e0c3ec6ea89eb..acf799e27344f 100644 --- a/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts +++ b/apps/meteor/client/views/root/hooks/customOAuth/useGithubOAuth.ts @@ -22,14 +22,12 @@ const Github = CustomOAuth.configureOAuthService('github', config); export const useGithubOAuth = () => { const enabled = useSetting('Accounts_OAuth_Github'); - const githubApiUrl = useSetting('API_GitHub_URL', ''); useEffect(() => { - if (enabled && githubApiUrl) { + if (enabled) { Github.configure({ ...config, - serverURL: githubApiUrl, }); } - }, [enabled, githubApiUrl]); + }, [enabled]); };