Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active May 29, 2020 21:12
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/1137bda0f76766b06082916fe4fc6d95 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/1137bda0f76766b06082916fe4fc6d95 to your computer and use it in GitHub Desktop.
Azure AD Authentication in WPF Application using MSAL
public partial class App : Application
{
private static string ClientId = "89866898-d443-442e-ad58-21b6b308a520";
private static string Tenant = "da41245a5-11b3-996c-00a8-4d99re19f292";
private static string Instance = "https://login.microsoftonline.com/";
public static IPublicClientApplication PublicClientApp { get; private set; }
static App()
{
PublicClientApp = PublicClientApplicationBuilder.Create(ClientId)
.WithAuthority($"{Instance}{Tenant}")
.WithRedirectUri("http://localhost")
.Build();
TokenCacheHelper.Bind(PublicClientApp.UserTokenCache);
}
private static void Log(LogLevel level, string message, bool containsPii)
{
string logs = ($"{level} {message}");
StringBuilder sb = new StringBuilder();
sb.Append(logs);
File.AppendAllText(System.Reflection.Assembly.GetExecutingAssembly().Location + ".msalLogs.txt", sb.ToString());
sb.Clear();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment