microsoftgraph / msgraph-sdk-dotnet-auth

Archived - use the TokenCredential classes provided by Azure.Identity. https://docs.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme
https://graph.microsoft.com
MIT License
78 stars 19 forks source link

AuthProvider "IntegratedWindowsAuthenticationProvider.Ctor not found" #107

Closed Maxinoume closed 3 years ago

Maxinoume commented 3 years ago

I'm trying to use Microsoft.Graph Api to get a list of users. I am able to authenticate on the api. I receive the Token and basic profile info upon login.

Then I am trying to use the Microsoft.Graph.Auth SDK/nuget found here to generate my requests. Here is a barebone example of what I am trying to do (you can also find this example in the doc of the package.

public void test()
{
    var clientApplication = PublicClientApplicationBuilder
        .Create(ClientId)
        .WithTenantId(TenantId)
        .Build();

    var authProvider = new IntegratedWindowsAuthenticationProvider(clientApplication);
    var graphClient = new GraphServiceClient(authProvider);

    var users = await graphClient.Users
        .Request()
        .GetAsync();
}

But I get the error System.MissingMethodException: 'Method not found: 'Void Microsoft.Graph.Auth.IntegratedWindowsAuthenticationProvider..ctor(Microsoft.Identity.Client.IPublicClientApplication, System.Collections.Generic.IEnumerable`1<System.String>)'.' before even entering the method test(). The message says it cannot find IntegratedWindowsAuthenticationProvider but the package is installed and I can navigate to the constructor (F12) without issue.

enter image description here

If I remove the line with IntegratedWindowsAuthenticationProvider, the code executes without crashing. And I can authenticate into the Api successfully. I tried moving the line after the successful authentication but I get the same error.

AB#9189

andrueastman commented 3 years ago

@Maxinoume Can you provide more info on the package version you are trying to use and the target version of .Net?

Maxinoume commented 3 years ago

I'm using the latest package version (v1.0.0-preview.7) and .Net 4.8. But I'd also like to use it on .Net Core 5. I've now just realized that it says to use .Net 4.5 but I can't do that because of other parts of the codebase.

Could this really be the problem? I'm surprised the manager let me install it if my project didn't meet the requirements.

Maxinoume commented 3 years ago

I saw that there were #IF NET45 in InteractiveAuthenticationProvider that most probably cause my issue. I cloned the solution on my end to try to fix the issue but when using this custom DLL, my project didn't recognize the controller Doesn't contain a controller with X parameters on build (instead of the similar exception but on execution with the unedited Nuget).

I didn't want to spend much time on this so I decided to go without this wrapper and just implement my own basic token handling. I don't need this issue fixed anymore so this issue can be closed if no effort wants to be wasted here.