Repository navigation
Description
Describe the bug
I’m using OAuth2PkceUtil.authorize() for desktop Google sign-in with useWebview: false. Cancellation is surfaced as an OAuth2PkceUnknownException, with the original PlatformException embedded in its message as a string:
OAuth2PkceUnknownException: Unexpected error during authorization: PlatformException(CANCELED, User canceled login, null, null)
#0 OAuth2PkceUtil.authorize (package:serverpod_auth_idp_flutter/src/common/oauth2_pkce/oauth2_pkce_util.dart:162:7)
<asynchronous suspension>
The underlying exception has the machine-readable code CANCELED, but the wrapper only exposes a message. There is no accessible original exception or cause from which to retrieve its structured fields.
An on PlatformException handler outside authorize() cannot handle this cancellation because the thrown object is already an OAuth2PkceUnknownException. Distinguishing cancellation from other failures consequently requires matching text within the wrapper’s message.
To reproduce
- Configure
OAuth2PkceUtilfor Google OAuth using the system browser, withuseWebview: false. - Call
await oauth.authorize(). - Close the browser entirely or just return to the flutter app desktop window without completing sign-in.
- Wait for the authorization attempt to finish and inspect the exception received by the caller.
- Observe that it is an
OAuth2PkceUnknownException, containing the string representation ofPlatformException(CANCELED, User canceled login, null, null).
Expected behavior
-
Surface cancellation through the existing
OAuth2PkceUserCancelledException. The underlyingCANCELEDcode provides the information needed to classify it. -
Preserve the original exception and its stack trace when wrapping unexpected failures, exposing them as accessible properties alongside the human-readable message.
This would allow applications to distinguish expected cancellation from sign-in failures and inspect the structured details of unexpected errors without parsing exception messages.
Library version
serverpod_auth_idp_flutter: 4.0.2flutter_web_auth_2: 5.0.3, resolved as a transitive dependency- Flutter: 3.47.8
- Dart: 3.13.7
Platform information
- Platform: Linux desktop
- Distribution: Fedora 43 (Workstation Edition)
- Browser: Chrome Version
157.0.8103.38(Official Build) (x86_64) - Authentication configuration:
useWebview: false
Additional context
Following a discussion with the Serverpod team, I was invited to submit a PR addressing this. I have a fix and regression tests ready, and I’m opening this issue to track the bug and link the accompanying PR.
How experienced are you with this library?
Expert - Experienced and comfortable with using this library in complex projects
Are you interested in working on a PR for this?
- I want to work on this
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog 🗂️
Activity