What would be the correct way to implement the Microsoft.Graph package into ABP app? InvalidOperationException: IDW10503

Junchang Lv (999008865) 1 Reputation point
2022-06-07T10:20:50.007+00:00
ABP Framework version: v5.2.2  
UI type: Razor Page  
DB provider: EF Core  

We are attempting to incorporate support for calling Microsoft Graph APIs in our ABP application, using the Microsoft.Graph package. We've already successfully implemented authentication using Azure AD accounts according to the directions in this post: https://community.abp.io/posts/how-to-use-the-azure-active-directory-authentication-for-mvc-razor-page-applications-4603b9cf (we used the second approach, using AddMicrosoftIdentityWebApp).

However, when attempting to use graph client to call API, it shows empty in provided scheme with InvalidOperationException: IDW10503. Here is the code for our ConfigureAuthentication function in the WebModule.cs file:

private void ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)
{
context.Services.AddAuthentication()
.AddJwtBearer(options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
options.Audience = "Portal";
})
.AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd"));
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { "User.Read" })
.AddMicrosoftGraph(configuration.GetSection("Graph"))
.AddInMemoryTokenCaches();

        context.Services.Configure<OpenIdConnectOptions>(OpenIdConnectDefaults.AuthenticationScheme, options =>  
        {  
            options.Authority = "https://login.microsoftonline.com/" + configuration["AzureAd:TenantId"] + "/v2.0/";  
            options.ClientId = configuration["AzureAd:ClientId"];  
            options.ResponseType = OpenIdConnectResponseType.CodeIdToken;  
            options.CallbackPath = configuration["AzureAd:CallbackPath"];  
            options.ClientSecret = configuration["AzureAd:ClientSecret"];  
            options.RequireHttpsMetadata = false;  
            options.SaveTokens = false;  
            options.GetClaimsFromUserInfoEndpoint = true;  

            options.SignInScheme = IdentityConstants.ExternalScheme;  

            options.ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");  
        });  
}  

The Exception is here.
An unhandled exception occurred while processing the request.
InvalidOperationException: IDW10503: Cannot determine the cloud Instance. The provided authentication scheme was ''.
Microsoft.Identity.Web inferred 'Identity.Application' as the authentication scheme. Available authentication schemes are
'idsrv,idsrv.external,Identity.Application,Identity.External,Identity.TwoFactorRememberMe,Identity.TwoFactorUserId,Bearer,Cookies,OpenIdConnect'. See https://aka.ms/id-web/authSchemes.
Microsoft.Identity.Web.TokenAcquisition.GetOptions(string authenticationScheme, out string effectiveAuthenticationScheme)

ServiceException: Code: generalException
Message: An error occurred sending the request.
Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
What would be the correct way to implement the Microsoft.Graph package into our ABP app? It seems something wrong in authentication schema configuration. We try to follow the guide from MS website to call the calendar event API.
https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-app-configuration?tabs=aspnetcore
https://learn.microsoft.com/en-us/learn/modules/msgraph-dotnet-core-access-user-events/5-app-access-events

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,161 Reputation points Microsoft Employee
    2022-06-10T06:50:13.35+00:00

    Hi JunchangLv999008865-9709 ,

    Thanks for reaching out to us ,

    you are trying to use graph service client to call API , could you please try the steps motioned in the doc - https://learn.microsoft.com/en-us/learn/modules/msgraph-dotnet-core-access-user-events/5-app-access-events

    Hope this will help

    Thanks
    Vicky Kumar

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.