Skip to content
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

feat(authorization): add initiateImplicitGrant function for OAuth Implicit Grant flow #4070

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

arun3528
Copy link
Collaborator

COMPLETES #< INSERT LINK TO ISSUE >

This pull request addresses

Introduced the initiateImplicitGrant function to facilitate the Implicit Grant flow for user authorization. The function constructs a login URL and handles the redirection either in a new window or the current window, based on the provided options.

  • Parameters:

    • options: Configures the login flow.
    • options.separateWindow: Determines if the login should open in a separate window. Can be a boolean or an object specifying window features. If true, opens a new window with default dimensions; if an object, allows custom window settings (e.g., {width: 800, height: 600}).
  • Returns: A Promise<void> that resolves immediately after initiating the login flow.

  • Error Handling: Throws an error if the login URL cannot be constructed or if there are issues opening a new window.

This function is typically invoked via AuthorizationBrowser#initiateLogin.

by making the following changes

< DESCRIBE YOUR CHANGES >

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

< ENUMERATE TESTS PERFORMED, WHETHER MANUAL OR AUTOMATED >

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

@arun3528 arun3528 requested review from a team as code owners January 21, 2025 21:47
Copy link

coderabbitai bot commented Jan 21, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
warning [email protected]: Glob versions prior to v9 are no longer supported
warning intern > [email protected]: Glob versions prior to v9 are no longer supported
warning intern > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jasmine > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > [email protected]: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-config > babel-jest > babel-plugin-istanbul > test-exclude > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > [email protected]: Glob versions prior to v9 are no longer supported
warning mocha > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning [email protected]: 16.1.1
warning wd > [email protected]: You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.

(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)
warning wd > archiver > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > [email protected]: request has been deprecated, see request/request#3142
warning wd > archiver > archiver-utils > [email protected]: Glob versions prior to v9 are no longer supported
warning wd > request > [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
warning wd > request > [email protected]: this library is no longer supported
warning @babel/cli > [email protected]: Glob versions prior to v9 are no longer supported
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
warning @babel/polyfill > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning @babel/runtime-corejs2 > [email protected]: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
warning babel-plugin-lodash > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > [email protected]: Glob versions prior to v9 are no longer supported
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > [email protected]: 16.1.1
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
warning workspace-aggregator-10c9356b-7c55-48d5-ae5e-ca3202df6ac8 > @babel/[email protected]: 🚨 This package has been deprecated in favor of separate inclusion of a polyfill and regenerator-runtime (when needed). See the @babel/polyfill docs (https://babeljs.io/docs/en/babel-polyfill) for more information.
error [email protected]: The engine "node" is incompatible with this module. Expected version "^14 || ^16 || ^17 || ^18 || ^19". Got "22.9.0"
error Found incompatible module.

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the OAuth login process across multiple files in the Webex authorization browser plugin. Key changes include enhancements to the initOauth function in app.js, which now determines whether to initiate the OAuth login in a separate window or the same window based on the iframe context. The initiateLogin and initiateImplicitGrant methods in the AuthorizationBrowser class have been updated with expanded documentation and logic to handle the separateWindow option, allowing for flexible window configurations. Additionally, the initiateAuthorizationCodeGrant method in the AuthorizationBrowserFirstParty class has been modified to incorporate similar handling for the separateWindow property. New test cases have been added to validate these functionalities, ensuring that the login process can be initiated with various window handling strategies. Overall, these changes enhance the OAuth flow initiation process for different application contexts.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arun3528 arun3528 added the validated If the pull request is validated for automation. label Jan 21, 2025
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-4070.d3m3l2kee0btzx.amplifyapp.com

Copy link
Contributor

@Shreyas281299 Shreyas281299 left a comment

Choose a reason for hiding this comment

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

Changes look good. Just remove the logs that are not required.

defaultWindowSettings,
typeof options.separateWindow === 'object' ? options.separateWindow : {}
);
console.error('windowFeatures112232');
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this log??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no just removed it can you check again i added more code in another package as well

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
packages/@webex/plugin-authorization-browser/src/authorization.js (1)

150-166: Consider adding security implications to documentation.

While the documentation is comprehensive, consider adding a note about potential security implications of opening the login in a new window, such as:

  • Popup blockers potentially blocking the window
  • The importance of proper origin validation in the OAuth flow
packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js (1)

454-488: Consider adding more edge cases to test suite.

The current tests cover the basic functionality well, but consider adding tests for:

  1. Window opening failures (popup blockers)
  2. Invalid window settings
  3. Security token validation in the new window context
packages/@webex/plugin-authorization-browser-first-party/src/authorization.js (1)

227-247: Consider extracting window handling logic to a shared utility.

The window handling logic is duplicated between this file and the main authorization plugin. Consider extracting it to a shared utility function to maintain consistency and reduce code duplication.

+ // In a new shared utility file (e.g., window-utils.js)
+ export const openLoginWindow = (webex, loginUrl, options) => {
+   if (options?.separateWindow) {
+     const defaultWindowSettings = {
+       width: 600,
+       height: 800
+     };
+     const windowSettings = Object.assign(
+       defaultWindowSettings,
+       typeof options.separateWindow === 'object' ? options.separateWindow : {}
+     );
+     const windowFeatures = Object.entries(windowSettings)
+       .map(([key, value]) => `${key}=${value}`)
+       .join(',');
+     return webex.getWindow().open(loginUrl, '_blank', windowFeatures);
+   }
+   webex.getWindow().location = loginUrl;
+ };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b7d89d9 and 9f116f3.

📒 Files selected for processing (3)
  • packages/@webex/plugin-authorization-browser-first-party/src/authorization.js (1 hunks)
  • packages/@webex/plugin-authorization-browser-first-party/test/unit/spec/authorization.js (1 hunks)
  • packages/@webex/plugin-authorization-browser/src/authorization.js (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/@webex/plugin-authorization-browser/src/authorization.js

[error] 167-167: expected , but instead found {

Remove {

(parse)


[error] 169-169: expected : but instead found .

Remove .

(parse)


[error] 169-169: expected , but instead found ;

Remove ;

(parse)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Initialize Project
  • GitHub Check: AWS Amplify Console Web Preview
🔇 Additional comments (1)
packages/@webex/plugin-authorization-browser/src/authorization.js (1)

116-135: Well-documented function signature!

The JSDoc comments are comprehensive and clearly explain the function's purpose, parameters, return type, and possible errors.

Comment on lines +174 to +194
if (options?.separateWindow) {
// Default window settings
const defaultWindowSettings = {
width: 600,
height: 800
};

// Merge user provided settings with defaults
const windowSettings = Object.assign(
defaultWindowSettings,
typeof options.separateWindow === 'object' ? options.separateWindow : {}
);
// Convert settings object to window.open features string
const windowFeatures = Object.entries(windowSettings)
.map(([key, value]) => `${key}=${value}`)
.join(',');
this.webex.getWindow().open(loginUrl, '_blank', windowFeatures);
} else {
// Default behavior - open in same window
this.webex.getWindow().location = loginUrl;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation and error handling for window operations.

Consider these improvements:

  1. Validate user-provided window settings to prevent security issues
  2. Add error handling for cases where window.open fails (e.g., popup blockers)
 if (options?.separateWindow) {
   // Default window settings
   const defaultWindowSettings = {
     width: 600,
     height: 800
   };

+  // Validate user settings
+  const validateSettings = (settings) => {
+    const allowedProps = ['width', 'height', 'menubar', 'toolbar'];
+    return Object.fromEntries(
+      Object.entries(settings).filter(([key, value]) => 
+        allowedProps.includes(key) && 
+        typeof value === 'number' || typeof value === 'string'
+      )
+    );
+  };

   // Merge user provided settings with defaults
   const windowSettings = Object.assign(
     defaultWindowSettings, 
-    typeof options.separateWindow === 'object' ? options.separateWindow : {}
+    typeof options.separateWindow === 'object' ? validateSettings(options.separateWindow) : {}
   );
   
   // Convert settings object to window.open features string
   const windowFeatures = Object.entries(windowSettings)
     .map(([key, value]) => `${key}=${value}`)
     .join(',');
-  this.webex.getWindow().open(loginUrl, '_blank', windowFeatures);
+  const newWindow = this.webex.getWindow().open(loginUrl, '_blank', windowFeatures);
+  if (!newWindow) {
+    throw new Error('Failed to open login window. Please check if popup blockers are enabled.');
+  }
 } else {
   // Default behavior - open in same window
   this.webex.getWindow().location = loginUrl;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (options?.separateWindow) {
// Default window settings
const defaultWindowSettings = {
width: 600,
height: 800
};
// Merge user provided settings with defaults
const windowSettings = Object.assign(
defaultWindowSettings,
typeof options.separateWindow === 'object' ? options.separateWindow : {}
);
// Convert settings object to window.open features string
const windowFeatures = Object.entries(windowSettings)
.map(([key, value]) => `${key}=${value}`)
.join(',');
this.webex.getWindow().open(loginUrl, '_blank', windowFeatures);
} else {
// Default behavior - open in same window
this.webex.getWindow().location = loginUrl;
}
if (options?.separateWindow) {
// Default window settings
const defaultWindowSettings = {
width: 600,
height: 800
};
// Validate user settings
const validateSettings = (settings) => {
const allowedProps = ['width', 'height', 'menubar', 'toolbar'];
return Object.fromEntries(
Object.entries(settings).filter(([key, value]) =>
allowedProps.includes(key) &&
typeof value === 'number' || typeof value === 'string'
)
);
};
// Merge user provided settings with defaults
const windowSettings = Object.assign(
defaultWindowSettings,
typeof options.separateWindow === 'object' ? validateSettings(options.separateWindow) : {}
);
// Convert settings object to window.open features string
const windowFeatures = Object.entries(windowSettings)
.map(([key, value]) => `${key}=${value}`)
.join(',');
const newWindow = this.webex.getWindow().open(loginUrl, '_blank', windowFeatures);
if (!newWindow) {
throw new Error('Failed to open login window. Please check if popup blockers are enabled.');
}
} else {
// Default behavior - open in same window
this.webex.getWindow().location = loginUrl;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants