Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X509CertificateAuthenticationProvider does not provide a way to specify IMsalHttpClientFactory #1496

Open
1 task done
SPWizard01 opened this issue Jul 9, 2024 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@SPWizard01
Copy link

Category

  • Bug

Describe the bug

When using this overload

public X509CertificateAuthenticationProvider(ILogger<OAuthAuthenticationProvider> logger, IMsalHttpClientFactory msalHttpClientFactory)
token acquisition for Client App will fail because confidentialClientApplication has not been built

Steps to reproduce

        services.AddPnPCore(options =>
        {

            //var defProvider = new X509CertificateAuthenticationProvider(LoggerFactory.Create((b) => { }).CreateLogger<OAuthAuthenticationProvider>(), new SimpleHttpClientFactory());
            //defProvider.TenantId = tenantId;
            //defProvider.ClientId = clientId;
            //defProvider.Certificate = GetCertificateFromStore(certThumbprint);
            //this will not work to acquire token
            //options.DefaultAuthenticationProvider = defProvider;
            options.DefaultAuthenticationProvider = new X509CertificateAuthenticationProvider(clientId, tenantId, GetCertificateFromStore(certThumbprint)); //does not work behind a corporate proxy as IMsalHttpClientFactory is always null
        });

Expected behavior

Expected behavior is to be able to initialize this provider with IMsalHttpClientFactory, reasoning being behind a corporate proxy, I need to specify custom HttpClientHandler (with Proxy).

Environment details (development & target environment)

  • SDK version: 1.13.0
  • OS: [e.g. Windows 11
  • SDK used in: Console App
  • Framework: .NET Core v8.x
  • Browser(s): Latest Edge
  • Tooling: Visual Studio 2022

Additional context

I was not able to find a suitable constructor for X509CertificateAuthenticationProvider so that I can provide certificate, tenantId, clientId, and a custom IMsalHttpClientFactory. Maybe I am doing something wrong.

Workaround is to of course create your own implementation of OAuthAuthenticationProvider

Thanks for your contribution! Sharing is caring.

@jansenbe jansenbe self-assigned this Jul 26, 2024
@jansenbe
Copy link
Contributor

@SPWizard01 : you can possibly configure the proxy for all used HttpClient instances via https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultproxy?view=net-8.0#remarks?

@jansenbe jansenbe added the question Further information is requested label Jul 26, 2024
@SPWizard01
Copy link
Author

You can, but, because of how corporate proxies are configured most often you don't want that :)

In my case I had to create my own provider based on the one you have.

To be fair the easiest approach is the one you suggested, it just does not always fit the need :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants