microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Bug] WithSSHCertificateAuthenticationScheme Not Return a SSH Certificate When WAM Enabled

Open msJinLei opened this issue 5 months ago • 4 comments

Library version used

4.61.3.0

.NET version

.netstandard 2.0

Scenario

PublicClient - desktop app

Is this a new or an existing app?

The app is in production, and I have upgraded to a new version of MSAL

Issue description and reproduction steps

Raised by @vthiebaut10, in Azure PowerShell, when WAM is enabled, the customer fails to retry to connect a configured Azure VM using Az.Ssh. Here are the steps to reproduce

When the WAM is disabled, Enter-AzVM works as expected. And we find when WAM is enabled, WithSSHCertificateAuthenticationScheme doesn't return a SSH certificate but return a bearer token. But WAM is disabled, it returns a SSH certficate.

Relevant code snippets

public virtual IPublicClientApplication CreatePublicClient(string authority, string tenantId)
{
    var builder = PublicClientApplicationBuilder.Create(Constants.PowerShellClientId);
    if (AzConfigReader.IsWamEnabled(authority))
    {
        builder = builder.WithBroker(new BrokerOptions(BrokerOptions.OperatingSystems.Windows));
    }
    if (!string.IsNullOrEmpty(authority))
    {
        builder.WithAuthority(authority, tenantId ?? organizationTenant);
    }
    var client = builder.Build();
    RegisterCache(client);
    return client;
}

var publicClient = CreatePublicClient(context.Environment.ActiveDirectoryAuthority, context.Tenant.Id)
var account = publicClient.GetAccountAsync(context.Account.GetProperty(AzureAccount.Property.HomeAccountId))
               .ConfigureAwait(false).GetAwaiter().GetResult();
var result = publicClient.AcquireTokenSilent(scopes, account)
             .WithSSHCertificateAuthenticationScheme(jwk, keyId)
             .ExecuteAsync();
var accessToken = result.ConfigureAwait(false).GetAwaiter().GetResult();

Expected behavior

Return a SSH certificate as non-broker public client does

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

msJinLei avatar Aug 28 '24 08:08 msJinLei