Skip to content

OAuth2PkceUtil misclassifies cancellation and loses structured error details #6051

Backlog

Description

@NonymousMorlock

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

  1. Configure OAuth2PkceUtil for Google OAuth using the system browser, with useWebview: false.
  2. Call await oauth.authorize().
  3. Close the browser entirely or just return to the flutter app desktop window without completing sign-in.
  4. Wait for the authorization attempt to finish and inspect the exception received by the caller.
  5. Observe that it is an OAuth2PkceUnknownException, containing the string representation of PlatformException(CANCELED, User canceled login, null, null).

Expected behavior

  1. Surface cancellation through the existing OAuth2PkceUserCancelledException. The underlying CANCELED code provides the information needed to classify it.

  2. 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.2
  • flutter_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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions