Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 30, 2020 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/af5e46a1fb80d373cc75284ca398141c to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/af5e46a1fb80d373cc75284ca398141c to your computer and use it in GitHub Desktop.
Azure AD B2C and MSAL, Embedded Custom Web UI for instantiating login window in .NET Core WPF App
internal class EmbeddedCustomWebUI : ICustomWebUi
{
public const int DefaultWindowWidth = 450;
public const int DefaultWindowHeight = 600;
private readonly Window _windowOwner;
private readonly string _windowTitle;
private readonly int _windowWidth;
private readonly int _windowHeight;
private readonly WindowStartupLocation _windowStartupLocation;
public EmbeddedCustomWebUI(Window owner,
string title = "Sign in",
int windowWidth = DefaultWindowWidth,
int windowHeight = DefaultWindowHeight,
WindowStartupLocation windowStartupLocation = WindowStartupLocation.CenterOwner)
{
_windowOwner = owner ?? throw new ArgumentNullException(nameof(owner));
_windowTitle = title;
_windowWidth = windowWidth;
_windowHeight = windowHeight;
_windowStartupLocation = windowStartupLocation;
}
public Task<Uri> AcquireAuthorizationCodeAsync(Uri authorizationUri, Uri redirectUri, CancellationToken cancellationToken)
{
var taskCompletion = new TaskCompletionSource<Uri>();
_windowOwner.Dispatcher.Invoke(() =>
{
new CustomLoginWindow(authorizationUri, redirectUri, taskCompletion, cancellationToken)
{
Owner = _windowOwner,
Title = _windowTitle,
Width = _windowWidth,
Height = _windowHeight,
WindowStartupLocation = _windowStartupLocation,
}.ShowDialog();
});
return taskCompletion.Task;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment