You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I want to use Microsoft.Identity.Client.Desktop for authorization via embedded WebView2 in WinUI3, my code for authorization is based on example at the bottom of question, because when I try to authorize via default Browser, after authorization it drops such exception:
Original exception: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
This code example works perfectly for WPF, but it doesn't work at all with WinUI 3
Observed Behavior
When I added library Microsoft.Identity.Client.Desktop to project with Microsoft.WindowsAppSdk and Microsoft.Graph, error was shown in building procedure:
error NETSDK1152: Found multiple publish output files with the same relative path:
There was also needed update of whole class, because Microsoft.Identity.Client 5.0.0+ doesn't contain for example DelegateAuthenticateProvider.
I tried to add extern aliases to WindowsAppSdk and Microsoft.Identity.Client.Desktop, so when app is compiled it should be recognized as other WebView2, but it hadn't helped. I also tried to add ignoring of error with duplicates using ErrorOnDuplicatePublishOutputFiles, but it hadn't helped also.
Steps to Reproduce
To reproduce this bug, you need to do this steps:
Download Microsoft.Identity.Client.Desktop, Microsoft.Graph and MicrosoftWindowsAppSdk
Copy this code:
public class AuthenticationHelper
{
static string clientId = App.Current.Resources["ida:ClientID"].ToString();
public static string[] Scopes = { "Files.Read" };
private static readonly IPublicClientApplication IdentityClientApp;
public static string TokenForUser = null;
public static DateTimeOffset Expiration;
private static GraphServiceClient graphClient = null;
static AuthenticationHelper()
{
IdentityClientApp = PublicClientApplicationBuilder.Create(clientId)
.WithDefaultRedirectUri()
.WithWindowsEmbeddedBrowserSupport()
.Build();
}
public static GraphServiceClient GetAuthenticatedClient()
{
if (graphClient == null)
{
// Create Microsoft Graph client.
try
{
graphClient = new GraphServiceClient(
"https://graph.microsoft.com/v1.0",
new DelegateAuthenticationProvider(
async (requestMessage) =>
{
var token = await GetTokenForUserAsync();
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
requestMessage.Headers.Add("SampleID", "uwp-csharp-photobrowser-sample");
}));
return graphClient;
}
catch (Exception ex)
{
Debug.WriteLine("Could not create a graph client: " + ex.Message);
}
}
return graphClient;
}
public static async Task<string> GetTokenForUserAsync()
{
AuthenticationResult authResult;
var accounts = await IdentityClientApp.GetAccountsAsync();
var firstAccount = accounts.FirstOrDefault();
try
{
authResult = await IdentityClientApp.AcquireTokenSilent(Scopes, firstAccount).ExecuteAsync();
TokenForUser = authResult.AccessToken;
}
catch (Exception ex)
{
//this.logger.Error(ex);
if (TokenForUser == null || Expiration <= DateTimeOffset.UtcNow.AddMinutes(5))
{
authResult = await IdentityClientApp.AcquireTokenInteractive(Scopes)
.WithAccount(firstAccount)
.WithPrompt(Microsoft.Identity.Client.Prompt.SelectAccount)
.WithUseEmbeddedWebView(true)
.ExecuteAsync();
TokenForUser = authResult.AccessToken;
Expiration = authResult.ExpiresOn;
}
}
return TokenForUser;
}
}
Thank you for help😊
The text was updated successfully, but these errors were encountered:
Category
Expected or Desired Behavior
Hi, I want to use Microsoft.Identity.Client.Desktop for authorization via embedded WebView2 in WinUI3, my code for authorization is based on example at the bottom of question, because when I try to authorize via default Browser, after authorization it drops such exception:
This code example works perfectly for WPF, but it doesn't work at all with WinUI 3
Observed Behavior
When I added library Microsoft.Identity.Client.Desktop to project with Microsoft.WindowsAppSdk and Microsoft.Graph, error was shown in building procedure:
error NETSDK1152: Found multiple publish output files with the same relative path:
MyProject\obj\x64\Debug\net7.0-windows10.0.19041.0\win10-x64\MsixContent\Microsoft.Web.WebView2.Core.dll
microsoft.web.webview2\1.0.864.35\lib\netcoreapp3.0\Microsoft.Web.WebView2.Core.dll.
There was also needed update of whole class, because Microsoft.Identity.Client 5.0.0+ doesn't contain for example DelegateAuthenticateProvider.
I tried to add extern aliases to WindowsAppSdk and Microsoft.Identity.Client.Desktop, so when app is compiled it should be recognized as other WebView2, but it hadn't helped. I also tried to add ignoring of error with duplicates using ErrorOnDuplicatePublishOutputFiles, but it hadn't helped also.
Steps to Reproduce
To reproduce this bug, you need to do this steps:
Thank you for help😊
The text was updated successfully, but these errors were encountered: