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

Feature/add openurl support

Open trevordunn opened this issue 2 months ago • 3 comments

This is a continuation of #393, which seems to have gone stale.

  • [x] All new/changed/fixed functionality is covered by tests (or N/A)
  • [x] I have added documentation for all new/changed functionality (or N/A)

📋 Changes

  • Adds support for the openUrl parameter in both loginWithRedirect and logout on the browser version.
  • openUrl requires auth0-spa-js version 2.0.1 or later.
  • It makes the lib more closely aligned with the auth0-spa-js lib which is used underneath.

This is important to me due to the @microsoft/teams-js library necessary to do authentication inside microsoft teams, reference docs here

In short, it handles authentication in its own window.

authentication.authenticate({
    url: window.location.origin + "/tab-auth/simple-start-v2",
    width: 600,
    height: 535})

My use case would be something similar to

auth0.loginWithRedirect(openUrl: (auth0Url) async {
  authentication.authenticate(
    url: "$auth0Url/tab-auth/simple-start-v2",
    width: 600,
    height: 535
  )
})

🎯 Testing

  • In order to test, replace the auth0-spa-js version from 2.0 to 2.0.1 at auth0_flutter/example/web/index.html
  • Add the snippet below to loginWithRedirect and logout functions
openUrl: (final url) async {
  debugPrint(url);
  window.location.replace(url);
}
  • Ensure you will see the urls printed on the console.

Possible concerns

While manual testing, you will also see two errors in the web console:

  • Error: Promise was rejected with a value of 'undefined'
  • TypeError: T.as is not a function

From my tests, this seems be comming out of the main auth0-spa-js library due to unhandled rejections, and doesn't affect the usage of auth0_flutter itself. Though it would require a deeper research on why it is happening.

trevordunn avatar Nov 24 '25 16:11 trevordunn