Skip to content

Commit

Permalink
perf(MSAL): Add AuthenticateAsync binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed May 19, 2023
1 parent 0529f85 commit ec977f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/AddIns/Uno.UI.MSAL/Uno.UI.MSAL.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Deterministic>true</Deterministic>
<AssemblyName>Uno.UI.MSAL</AssemblyName>
<RootNamespace>Uno.UI.MSAL</RootNamespace>
Expand Down
19 changes: 18 additions & 1 deletion src/AddIns/Uno.UI.MSAL/WasmWebUi.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,38 @@
using Microsoft.Identity.Client.Extensibility;
using Uno.Foundation;

#if NET7_0_OR_GREATER
using System.Runtime.InteropServices.JavaScript;
#endif

namespace Uno.UI.MSAL
{
internal class WasmWebUi : ICustomWebUi
internal partial class WasmWebUi : ICustomWebUi
{
internal static readonly WasmWebUi Instance = new WasmWebUi();

public async Task<Uri> AcquireAuthorizationCodeAsync(Uri authorizationUri, Uri redirectUri, CancellationToken cancellationToken)
{
#if NET7_0_OR_GREATER
var uri = await NativeMethods.AuthenticateAsync(authorizationUri.OriginalString, redirectUri.OriginalString, "Sign in", 483, 600);
#else
var urlNavigate = WebAssemblyRuntime.EscapeJs(authorizationUri.OriginalString);
var urlRedirect = WebAssemblyRuntime.EscapeJs(redirectUri.OriginalString);

var js = $@"MSAL.WebUI.authenticate(""{urlNavigate}"", ""{urlRedirect}"", ""Sign in"", 483, 600);";

var uri = await WebAssemblyRuntime.InvokeAsync(js);
#endif

return new Uri(uri);
}

#if NET7_0_OR_GREATER
internal static partial class NativeMethods
{
[JSImport("globalThis.MSAL.WebUI.authenticate")]
internal static partial Task<string> AuthenticateAsync(string urlNavigate, string urlRedirect, string title, int popupWidth, int popupHeight);
}
#endif
}
}

0 comments on commit ec977f6

Please sign in to comment.