PostIt.Android: drive the PKCE flow through Chrome Custom Tabs
The earlier commit removed the client_secret and wired
MainActivity.OnNewIntent to AndroidOidcCallbackSink, but
IdentityModel.OidcClient.LoginAsync still had no IBrowser to drive
the user-agent half of the flow. Without it, the desktop / browser
projects continue to fail at login with 'No browser is available'.
Android now plugs in Chrome Custom Tabs:
* PostIt.Android/Services/AndroidSystemBrowser.cs implements
IBrowser.InvokeAsync using CustomTabsIntent.LaunchUrl and waits
for MainActivity.AndroidOidcCallbackSink to deliver the deep-link
Intent (android://postit-signin?code=...&state=...).
* PostIt/Services/Platform.cs is a tiny static indirection the
shared library uses to ask the running platform for an
IBrowser and the appropriate default RedirectUri, without
referencing any UI framework from the shared assembly.
* LoginPageViewModel reads Platform.DefaultRedirectUri and
Platform.CreateBrowser().Invoke() before calling LoginAsync.
* PostIt.Android/PlatformBootstrap.cs wires the Android side at
startup, and MainActivity.OnCreate calls EnsureInitialized().
* Xamarin.AndroidX.Browser 1.8.0 added to the central package
versions so CustomTabsIntent resolves.
This commit is contained in:
parent
512a0ef06f
commit
c172d1cf9e
7 changed files with 177 additions and 6 deletions
29
src/PostIt/PostIt.Android/PlatformBootstrap.cs
Normal file
29
src/PostIt/PostIt.Android/PlatformBootstrap.cs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
using PostIt.Services;
|
||||
using PostIt.Android.Services;
|
||||
|
||||
namespace PostIt.Android;
|
||||
|
||||
/// <summary>
|
||||
/// One-shot platform bootstrap. Called from
|
||||
/// <see cref="MainActivity.OnCreate"/> so that the shared
|
||||
/// <c>LoginPageViewModel</c> sees the Android-specific redirect URI and a
|
||||
/// working <c>IBrowser</c> (Chrome Custom Tabs) without referencing
|
||||
/// Android APIs from the shared library.
|
||||
/// </summary>
|
||||
internal static class PlatformBootstrap
|
||||
{
|
||||
private static int _initialized;
|
||||
|
||||
internal static void EnsureInitialized()
|
||||
{
|
||||
if (System.Threading.Interlocked.Exchange(ref _initialized, 1) != 0)
|
||||
return;
|
||||
|
||||
Platform.DefaultRedirectUri = Settings.AndroidRedirectUri;
|
||||
Platform.CreateBrowser = () =>
|
||||
{
|
||||
var activity = MainActivity.Current;
|
||||
return activity is null ? null : new AndroidSystemBrowser(activity);
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue