auth0-react icon indicating copy to clipboard operation
auth0-react copied to clipboard

Add setAuthCallbackUrl method for manual authentication handling

Open Toubat opened this issue 9 months ago • 0 comments

Description

This PR adds a new method setAuthCallbackUrl to the Auth0 context, allowing developers to manually set and process authentication callback URLs without relying on page reloads.

The primary benefits include:

  • Improved Electron support: In Electron and other native desktop applications, handling auth redirects through page reloads can be problematic as they may require special handling in the main process. This method provides a more direct approach.

  • Enhanced control over auth flow: Developers can now intercept OAuth callback URLs from custom URL schemes / deep links (like electron-fiddle://, file://, etc.) and manually pass them to Auth0 for processing.

The implementation ensures that after processing, the auth state is properly reset, preventing duplicate processing while maintaining the security of the authentication flow.

Testing

New test cases have been added to verify:

  • The method processes callback URLs with proper auth parameters across various URL schemes (https, http, file, chrome-extension, electron)
  • Setting the callback URLs without valid auth parameters are not processed
  • After processing, the auth state is properly reset, preventing duplicate auth processing on rerenders
  • Various URL formats are correctly handled according to Auth0's requirements

All existing tests pass, and code coverage has been maintained at 100%.

Checklist

  • [x] I have added documentation for the new functionality in the JSDoc comments
  • [ ] All active GitHub checks for tests, formatting, and security are passing
  • [x] The correct base branch is being used

Toubat avatar Apr 26 '25 21:04 Toubat