Reputation: 1
I have used Asp.net core 6 with OpenIdConnectDefaults.AuthenticationScheme
Authentication include MicrosoftGraph
. It is working fine when first time we login on the web application. But If user login and become ideal for some time then refresh the page, all functionality on application is working fine but when I am using MicroSoftGraphAPI
then getting exception.
GeneralException Message: An error occurred sending the request.
Here Program.cs code for Authentication:
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie(options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
}).AddMicrosoftIdentityWebApp(options =>
{
builder.Configuration.GetSection("AzureAd").Bind(options);
options.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
options.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
}, null, OpenIdConnectDefaults.AuthenticationScheme, null)
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddMicrosoftGraph(builder.Configuration.GetSection("MicrosoftGraph"))
.AddInMemoryTokenCaches(options =>
{
options.AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(90);
});
and stack trace exception:
at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) at Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) at Microsoft.Graph.UserRequest.GetAsync(CancellationToken cancellationToken) at FSOCore.GraphApi.GraphApiClientUI.GetGraphApiUser(String emailId) in ...\GraphApi\GraphApiClientUI.cs:line 20 at ../Controllers.CustomerController.GetGraphAPIUserName(IFormCollection formcollection) in ..\Controllers\CustomerController.cs:line 369
I try to find solution from google and tried so many but none of them works.
I have tried to pass ClientSecretCredential
during object creation of GraphServiceClient
class on program.cs but It did not work.
Expectation:
If I did something wrong on the Authentication on program.cs or should I add some more code lines regarding token management then suggest me, I will try to find solution.
Upvotes: 0
Views: 814