Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android WebAuth callback for system browser flows #15187

Merged
merged 2 commits into from
May 26, 2023

Conversation

Redth
Copy link
Member

@Redth Redth commented May 19, 2023

Description of Change

This was actually found somewhat by accident. On Android 11 (API30) and newer, you are required to declare in the manifest of your app intent queries if you want to be able to resolve intents from other packages than your own. The docs already describe this.

If you do not add the info to your manifest, the API will not resolve custom tabs and act as if your system does not support them. In this case we defer to using the system default browser (we just use a generic Action.VIEW + URI).

When this happens, and eventually the flow calls back to your callback activity, we were assuming that custom tabs were used and so we would route the callback to the intermediate activity (which is needed for custom tabs to clean up the custom tab - that's another story), but that callback would fail because we were missing bundle extras that are set only for custom tabs flows.

This PR adds some tracking state to know which type of flow we launched from so that the callback knows the appropriate action to take to complete the flow.

Issues Fixed

This adds a flag to track if the web authentication flow was launched via custom tabs or the fallback, system browser.

We were assuming it was always via custom tabs, and so the intermediate activity would be started which is not necessary or designed to compatible with the flow using the system browser.

This changes the callback activity to properly route back to the intermediate activity for custom tabs initialized flows, and to just call the OnResume callback for other flows (system browser).
@github-actions
Copy link
Contributor

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

@Eilon Eilon added the area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info label May 22, 2023
@mattleibow mattleibow merged commit 68bf07f into main May 26, 2023
@mattleibow mattleibow deleted the dev/redth/essentials-callback-android-nullreffix branch May 26, 2023 08:55
@mattleibow mattleibow added the backport/suggested The PR author or issue review has suggested that the change should be backported. label May 29, 2023
rmarinho pushed a commit that referenced this pull request May 30, 2023
* Fix Android WebAuth callback for system browser

This adds a flag to track if the web authentication flow was launched via custom tabs or the fallback, system browser.

We were assuming it was always via custom tabs, and so the intermediate activity would be started which is not necessary or designed to compatible with the flow using the system browser.

This changes the callback activity to properly route back to the intermediate activity for custom tabs initialized flows, and to just call the OnResume callback for other flows (system browser).

* Auto-format source code

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
@hartez hartez added the backport/approved After some discussion or review, this PR or change was approved to be backported. label May 31, 2023
@hartez
Copy link
Contributor

hartez commented Jun 1, 2023

/backport to net7.0

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

Started backporting to net7.0: https://github.com/dotnet/maui/actions/runs/5138834817

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

@hartez backporting to net7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix Android WebAuth callback for system browser
.git/rebase-apply/patch:24: trailing whitespace.
			
.git/rebase-apply/patch:77: trailing whitespace.
			} 
warning: 2 lines add whitespace errors.
Using index info to reconstruct a base tree...
M	src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs
M	src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs
CONFLICT (content): Merge conflict in src/Essentials/src/WebAuthenticator/WebAuthenticator.shared.cs
Auto-merging src/Essentials/src/WebAuthenticator/WebAuthenticator.android.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Fix Android WebAuth callback for system browser
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

@github-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2023

@hartez an error occurred while backporting to net7.0, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

hartez added a commit that referenced this pull request Jun 2, 2023
* Fix Android WebAuth callback for system browser

This adds a flag to track if the web authentication flow was launched via custom tabs or the fallback, system browser.

We were assuming it was always via custom tabs, and so the intermediate activity would be started which is not necessary or designed to compatible with the flow using the system browser.

This changes the callback activity to properly route back to the intermediate activity for custom tabs initialized flows, and to just call the OnResume callback for other flows (system browser).

* Auto-format source code

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
PureWeen pushed a commit that referenced this pull request Jun 2, 2023
* Fix Android WebAuth callback for system browser

This adds a flag to track if the web authentication flow was launched via custom tabs or the fallback, system browser.

We were assuming it was always via custom tabs, and so the intermediate activity would be started which is not necessary or designed to compatible with the flow using the system browser.

This changes the callback activity to properly route back to the intermediate activity for custom tabs initialized flows, and to just call the OnResume callback for other flows (system browser).

* Auto-format source code

---------

Co-authored-by: GitHub Actions Autoformatter <autoformat@example.com>
@github-actions github-actions bot locked and limited conversation to collaborators Dec 10, 2023
@samhouts samhouts added the fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! label Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info backport/approved After some discussion or review, this PR or change was approved to be backported. backport/suggested The PR author or issue review has suggested that the change should be backported. fixed-in-8.0.0-preview.5.8529 Look for this fix in 8.0.0-preview.5.8529! platform/android 🤖
Projects
None yet
5 participants