Skip to content

fix: Handle OAuth2 PKCE cancellation and preserve error causes - #6053

Open
NonymousMorlock wants to merge 2 commits into
serverpod:mainfrom
NonymousMorlock:fix/oauth-pkce-cancellation
Open

NonymousMorlock wants to merge 2 commits into
serverpod:mainfrom
NonymousMorlock:fix/oauth-pkce-cancellation

Conversation

@NonymousMorlock

@NonymousMorlock NonymousMorlock commented Nov 25, 2026 •

Copy link
Copy Markdown

OAuth2PkceUtil.authorize() wraps platform cancellation as an OAuth2PkceUnknownException and embeds the underlying exception in its message, preventing callers from reliably inspecting its structured fields.

This change:

  • Maps platform errors with code CANCELED to the existing OAuth2PkceUserCancelledException.
  • Adds optional rawException and rawStackTrace properties to OAuth2PkceUnknownException, populated when wrapping unexpected failures.
  • Adds regression tests covering cancellation, preservation of platform error codes and messages, and preservation of generic exception identity and stack traces.

Fixes #6051

Validation:

  • flutter test --no-pub test/common/oauth2_pkce/oauth2_pkce_util_test.dart — all three tests passed.
  • Static analysis of the affected utility and tests — no issues found.
  • Formatting and whitespace checks passed.

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.
  • I added a changelog entry to changelog.d (dart run melos run changelog_add), or this change does not need one.

Breaking changes

Cancellation now throws the existing OAuth2PkceUserCancelledException instead of OAuth2PkceUnknownException, correcting the documented cancellation behavior.

Existing OAuth2PkceUnknownException constructor calls remain valid; the new named parameters are optional.

- Map canceled platform errors to OAuth2PkceUserCancelledException.
- Preserve original exceptions and stack traces in unexpected errors, with regression tests covering both platform and generic failures.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@NonymousMorlock

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth2PkceUtil misclassifies cancellation and loses structured error details

1 participant