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