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

Upgrade 4.50 sdk to 5.0 - Reference to type IAuthenticationProvider claims it is defined in Microsoft.Graph.Core, but cannot be found #1695

Closed
travaille-dev opened this issue Mar 8, 2023 · 5 comments

Comments

@travaille-dev
Copy link

travaille-dev commented Mar 8, 2023

Describe the bug
I went ahead and upgraded my Microsoft.Graph nuget package from 4.5 to 5.0.
After going through the docs and referencing the new Microsoft.Graph.Models library and updating the actual Mail api call ->

I'm getting an error of System.TypeLoadException: Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. once I make a request (to get a basic inbox fetch for the current logged in user).

I thought that there might be something wrong with how I'm registering the microsoft graph client in my Program.cs. I chose a different override for the .AddMicrosoftGraph function and now I receive a compiler error preventing the build of the solution.

Error
CS7069: Reference to type 'IAuthenticationProvider' claims it is defined in 'Microsoft.Graph.Core', but it could not be found

To Reproduce
This might be a little complicated, but I've just got an aspnet core hosted Blazor project. In my server project of this I've got an "on behalf of" flow going to have the Blazor page -> call Server endpoint -> then calls the microsoft graph.

Relevant Program.cs

builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApi(options =>
    {
        builder.Configuration.Bind("AzureAd", options);
        options.TokenValidationParameters.RoleClaimType =
            "http://schemas.microsoft.com/ws/2008/06/identity/claims/role";
    },
    options => { builder.Configuration.Bind("AzureAd", options); })
    .EnableTokenAcquisitionToCallDownstreamApi(options =>
    {
        options.ClientId = clientId;
        options.ClientSecret = clientSecret;
        options.TenantId = tenantId;
        options.Instance = builder.Configuration.GetValue<string>("AzureAd:Instance");
    }).AddMicrosoftGraph(graphBaseUri, graphScopes)
    .AddInMemoryTokenCaches();

Dummy Graph Controller

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Identity.Web.Resource;
using Microsoft.Graph;
using Microsoft.Graph.Models;

namespace Agora.Server.Controllers;
[Authorize]
[ApiController]
[Route("[controller]")]
[RequiredScope(RequiredScopesConfigurationKey = "AzureAd__Scopes")]
public class GraphServiceController : ControllerBase
{
    private readonly GraphServiceClient _graphServiceClient;
    private readonly ILogger<GraphServiceController> _logger;
    private const string ServiceName = "GraphService";

    public GraphServiceController(GraphServiceClient graphServiceClient, ILogger<GraphServiceController> logger)
    {
        _graphServiceClient = graphServiceClient;
        _logger = logger;
    }

    [HttpGet]
    [Route(nameof(GetMail))]
    public async Task<List<Message>> GetMail()
    {
        var messages = await _graphServiceClient.Me.Messages.GetAsync();
        _logger.Log(LogLevel.Information, "GetMail called");
        if (messages is not null && messages.Value is not null)
            return messages.Value.ToList();
        else
            return new List<Message>();
    }
}

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: [iOS]
  • Browser [firefox]
  • Version [110.0.1]

Additional context
I've tried explicitly including the 3.0.1 version of the Microsoft.Graph.Core nuget package, but my issue is not resolved.

I'm open to other ways of implementing on behalf of flow. Adding relevant doc Microsoft Doc

@ghost ghost added the Needs: Triage label Mar 8, 2023
@travaille-dev travaille-dev changed the title Upgrade 4.5 sdk to 5.0 - Reference to type IAuthenticationProvider claims it is defined in Microsoft.Graph.Core, but cannot be found Upgrade 4.50 sdk to 5.0 - Reference to type IAuthenticationProvider claims it is defined in Microsoft.Graph.Core, but cannot be found Mar 8, 2023
@svrooij
Copy link
Contributor

svrooij commented Mar 9, 2023

Maybe this code can give you some pointers, I was facing similar problem in Blazor WebAssembly (wanted to call Graph directly instead of building yet another proxy to graph). https://github.com/svrooij/BlazorGraphExplorer/commits/graph-v5/BlazorGraphExplorer

@benjamin79
Copy link

I´ve the same error.

Steps:
Create sample project in VS2022 with authentication and Graph -> works
Update Graph Core to 3.01 and Graph to. 5.1 ->

Could not load type 'Microsoft.Graph.IAuthenticationProviderOption' from assembly 'Microsoft.Graph.Core

Please help

@andrueastman
Copy link
Member

The call to AddMicrosoftGraph takes a dependecy on Microsoft.Identity.Web which will be updated to use version 5 to use the updated interfaces.

@benjamin79 Any chance you can confirm if the upgrade is from v4 to v5?

@benjamin79
Copy link

@andrueastman yes, the one vs2022 installs automatically with the template is v4. I then updated the libs

@travaille-dev
Copy link
Author

Thank you @andrueastman, I've found a relevant issue in the Microsoft.Identity.Web repository here

I think this issue would be okay to close out since it's not up to the sdk to update, but it would be nice to note in some documentation the current limitations on upgrading since the default projects for blazor with auth include Microsoft.Identity.Web. Like here

And thank you @svrooij for the gist. It does help for testing the new sdk directly from our client project.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants