private async Task <IPublicClientApplication> CreatePublicClientApplicationAsync(string authority, string clientId, Uri redirectUri) { var httpFactoryAdaptor = new MsalHttpClientFactoryAdaptor(Context.HttpClientFactory); var appBuilder = PublicClientApplicationBuilder.Create(clientId) .WithAuthority(authority) .WithRedirectUri(redirectUri.ToString()) .WithHttpClientFactory(httpFactoryAdaptor); // Listen to MSAL logs if GCM_TRACE_MSAUTH is set if (Context.Settings.IsMsalTracingEnabled) { // If GCM secret tracing is enabled also enable "PII" logging in MSAL bool enablePiiLogging = Context.Trace.IsSecretTracingEnabled; appBuilder.WithLogging(OnMsalLogMessage, LogLevel.Verbose, enablePiiLogging, false); } IPublicClientApplication app = appBuilder.Build(); // Register the application token cache await RegisterTokenCacheAsync(app); return(app); }
private async Task <IPublicClientApplication> CreatePublicClientApplicationAsync(string authority, string clientId, Uri redirectUri) { var httpFactoryAdaptor = new MsalHttpClientFactoryAdaptor(Context.HttpClientFactory); var appBuilder = PublicClientApplicationBuilder.Create(clientId) .WithAuthority(authority) .WithRedirectUri(redirectUri.ToString()) .WithHttpClientFactory(httpFactoryAdaptor); // Listen to MSAL logs if GCM_TRACE_MSAUTH is set if (Context.Settings.IsMsalTracingEnabled) { // If GCM secret tracing is enabled also enable "PII" logging in MSAL bool enablePiiLogging = Context.Trace.IsSecretTracingEnabled; appBuilder.WithLogging(OnMsalLogMessage, LogLevel.Verbose, enablePiiLogging, false); } // If we have a parent window ID we should tell MSAL about it so it can parent any authentication dialogs // correctly. We only support this on Windows right now as MSAL only supports embedded/dialogs on Windows. if (PlatformUtils.IsWindows() && !string.IsNullOrWhiteSpace(Context.Settings.ParentWindowId) && int.TryParse(Context.Settings.ParentWindowId, out int hWndInt) && hWndInt > 0) { appBuilder.WithParentActivityOrWindow(() => new IntPtr(hWndInt)); } IPublicClientApplication app = appBuilder.Build(); // Register the application token cache await RegisterTokenCacheAsync(app); return(app); }