Skip to content

chore: remove dependency on meteor's oauth packages #35877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

pierre-lehnen-rc
Copy link
Contributor

@pierre-lehnen-rc pierre-lehnen-rc commented Apr 25, 2025

Proposed changes (including videos or screenshots)

We already overwrite the client code for all of OAuth providers from meteor packages. This PR is reorganizing it a bit and also bringing the server code from those package so that we may drop the dependencies to those packages.

Issue(s)

Steps to test or reproduce

Further comments

haven't tested anything yet.

Providers:

  • accounts-github
  • github-oauth
  • accounts-twitter
  • twitter-oauth
  • accounts-facebook
  • facebook-oauth
  • accounts-google
  • google-oauth
  • accounts-meteor-developer
  • meteor-developer-oauth

Extras, maybe:

  • accounts-oauth
  • oauth1
  • oauth2
  • oauth

Copy link
Contributor

dionisio-bot bot commented Apr 25, 2025

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Apr 25, 2025

⚠️ No Changeset found

Latest commit: cb4b059

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

kodus-ai bot commented Apr 25, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@@ -15,15 +15,15 @@ rocketchat:user-presence

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Documentation and Comments critical

The removal of accounts-github and accounts-twitter packages should be documented in the changelog or migration guide as it's a breaking change for users relying on these authentication methods.

This issue appears in multiple locations:

  • apps/meteor/.meteor/packages: Lines 15-15
  • apps/meteor/.meteor/packages: Lines 15-15
    Please document the removal of these packages in the changelog or migration guide to inform users of this breaking change.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

`?client_id=${config.clientId}` +
`&scope=${flatScope}` +
`&redirect_uri=${OAuth._redirectUri('github', config)}` +
`&state=${OAuth._stateParam(loginStyle, credentialToken, options.redirectUrl)}${allowSignup}`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Potential Issues high

&state=${OAuth._stateParam(loginStyle, credentialToken, options?.redirectUrl)}${allowSignup}`;

The code accesses options.redirectUrl directly without checking if options is null or undefined, which could lead to runtime errors.

This issue appears in multiple locations:

  • apps/meteor/client/meteorOverrides/login/github.ts: Lines 27-27
  • apps/meteor/client/meteorOverrides/login/github.ts: Lines 27-27
    Please use optional chaining (options?.redirectUrl) to safely access redirectUrl and prevent runtime errors.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +70 to +72
} catch (err) {
return [];
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Error Handling high

} catch (err) {
	console.error('Failed to fetch GitHub emails:', err);
	return [];
}

The catch block in the getEmails function suppresses errors without logging, which makes debugging difficult.

This issue appears in multiple locations:

  • apps/meteor/server/configuration/oauth/github.ts: Lines 70-72
  • apps/meteor/server/configuration/oauth/github.ts: Lines 70-72
    Please log errors in the catch block to aid debugging instead of silently returning an empty array.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +13 to +18
return _updateOAuthServices();
});

settings.watchByRegex(/^Accounts_OAuth_Custom-[a-z0-9_]+/, (key, value) => {
if (!value) {
return removeOAuthService(key);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Error Handling high

settings.watchByRegex(/^Accounts_OAuth_.+/, async () => {
		try {
			return await _updateOAuthServices();
		} catch (error) {
			console.error('Error updating OAuth services:', error);
		}
	});

	settings.watchByRegex(/^Accounts_OAuth_Custom-[a-z0-9_]+/, async (key, value) => {
		if (!value) {
			try {
				return await removeOAuthService(key);
			} catch (error) {
				console.error(`Error removing OAuth service ${key}:`, error);
			}
		}
	});

The callback functions provided to settings.watchByRegex lack explicit error handling, which could lead to unhandled exceptions.

This issue appears in multiple locations:

  • apps/meteor/server/configuration/oauth/index.ts: Lines 13-18
  • apps/meteor/server/configuration/oauth/index.ts: Lines 13-18
    Please wrap the calls within these callbacks in try...catch blocks to handle potential errors gracefully.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

};

return registerOAuth1Service('twitter', urls, async (oauthBinding) => {
const response = await oauthBinding.getAsync('https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Error Handling high

try {
  const response = await oauthBinding.getAsync('https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true');
  
  // Optional: Add checks for response status or structure before destructuring
  if (!response || !response.data) {
    // Or handle based on specific error structure if provided by getAsync
    throw new Error('Failed to fetch user identity from Twitter or invalid response structure.');
  }
  const { data: identity } = response;

  // ... (rest of the processing identity) ...
  const fields = whitelistedFields.reduce(/* ... */);
  const serviceData = { /* ... */ };

  return {
    serviceData,
    options: {
      profile: {
        name: identity.name,
      },
    },
  };
} catch (error) {
  // Log the error and potentially re-throw or handle it as appropriate
  // for the registerOAuth1Service callback context.
  console.error('Error fetching Twitter user identity:', error);
  throw new Error(`Failed to fetch user identity from Twitter. ${error instanceof Error ? error.message : String(error)}`);
}

The API call to oauthBinding.getAsync lacks explicit error handling, which could lead to unhandled promise rejections or runtime errors.

This issue appears in multiple locations:

  • apps/meteor/server/configuration/oauth/twitter.ts: Lines 24-52
  • apps/meteor/server/configuration/oauth/twitter.ts: Lines 24-52
    Please wrap the API call and subsequent processing in a try...catch block to gracefully handle potential failures.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Comment on lines +12 to +16
settings.watchByRegex(/^Accounts_OAuth_.+/, () => {
return _updateOAuthServices();
});

settings.watchByRegex(/^Accounts_OAuth_Custom-[a-z0-9_]+/, (key, value) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Potential Issues medium

settings.watchByRegex(/^Accounts_OAuth_(?!Custom-).+/, () => { // Exclude Custom OAuth
		return _updateOAuthServices();
	});

	settings.watchByRegex(/^Accounts_OAuth_Custom-[a-z0-9_]+/, (key, value) => {

The regular expression /^Accounts_OAuth_.+/ is too broad and overlaps with custom OAuth settings, potentially causing redundant operations.

This issue appears in multiple locations:

  • apps/meteor/server/configuration/oauth/index.ts: Lines 12-16
  • apps/meteor/server/configuration/oauth/index.ts: Lines 12-16
    Please refine the regex to exclude custom settings using a negative lookahead (/^Accounts_OAuth_(?!Custom-).+/).

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

export const registerOAuth1Service = (
serviceName: string,
urls: IOAuth1Urls,
handleOauthRequest: (binding: IOAuth1Binding, query?: Record<string, any>) => Promise<HandledOauthRequest>,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Potential Issues medium

handleOauthRequest: (binding: IOAuth1Binding, query?: Record<string, unknown>) => Promise<HandledOauthRequest>,

The query parameter in the handleOauthRequest function uses Record<string, any>, which bypasses type checking and can hide runtime errors.

This issue appears in multiple locations:

  • apps/meteor/server/configuration/oauth/registerOAuth1Service.ts: Lines 7-7
  • apps/meteor/server/configuration/oauth/registerOAuth1Service.ts: Lines 7-7
    Please replace any with unknown or a more specific type for the query parameter to enhance type safety.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.


[email protected]
[email protected]
# oauth1 is used only by twitter oauth
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Documentation and Comments medium

# oauth1 is used for OAuth 1.0 implementations

The comment about oauth1 being used only by Twitter OAuth is misleading since accounts-twitter has been removed.

This issue appears in multiple locations:

  • apps/meteor/.meteor/packages: Lines 25-25
  • apps/meteor/.meteor/packages: Lines 25-25
    Please update the comment to reflect the general purpose of OAuth1 or remove it entirely.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

Copy link
Contributor

PR Preview Action v1.6.1

🚀 View preview at
https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-35877/

Built to branch gh-pages at 2025-04-25 00:44 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 28.57143% with 30 lines in your changes missing coverage. Please review.

Project coverage is 61.21%. Comparing base (72dfcf8) to head (cb4b059).
Report is 4 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #35877      +/-   ##
===========================================
+ Coverage    61.17%   61.21%   +0.04%     
===========================================
  Files         3005     3009       +4     
  Lines        71381    71477      +96     
  Branches     16341    16343       +2     
===========================================
+ Hits         43664    43753      +89     
- Misses       24748    24754       +6     
- Partials      2969     2970       +1     
Flag Coverage Δ
e2e 57.85% <28.57%> (-0.02%) ⬇️
unit 75.09% <ø> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant