Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Microsoft Outlook connection using Graph #12032


User avatar
0
Bernard created

Hi,

I'm trying to implement the ability to read Outlook emails in my application (https://learn.microsoft.com/en-us/training/modules/msgraph-dotnet-core-show-user-emails/1-introduction), but I'm facing a problem because Graph needs to launch the services services // Add support for OpenId authentication .AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme) failed

because an OpendConnectId Schema already exists

I think This code causes issue in Startup.cs

services // 2. Add support for OpenId authentication

.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)

.AddMicrosoftIdentityWebApp(Configuration)

How to fix this problem THANKS


32 Answer(s)
  • User Avatar
    0
    Bernard created

    ok, thks but after changing in Startup app.UseEndpoints(endpoints => { // For Dashboard Elsa endpoints.MapRazorPages(); the message is still the same : Status Code: 0 Microsoft.Graph.ServiceException: Code: generalException Message: An error occurred sending the request.

    ---> System.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 'Identity.Application,Identity.External,Identity.TwoFactorRememberMe,Identity.TwoFactorUserId,OpenIdConnect,AzureAd'. See https://aka.ms/id-web/authSchemes. at Microsoft.Identity.Web.TokenAcquisitionAspnetCoreHost.GetOptions(String authenticationScheme, String& effectiveAuthenticationScheme)

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @Bernard,

    I reproduced the error. I will try to fix this. Thanks for your feedback

  • User Avatar
    0
    Bernard created

    Thks very much !

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @Bernard,

    Could you update GraphEmailClient to following code

    // Get initial page of messages
    pagedMessages = await _graphServiceClient.Me.Messages
            .Request()
            .WithAuthenticationScheme("AzureAd")
            .Select(msg => new
            {
                msg.Subject,
                msg.BodyPreview,
                msg.ReceivedDateTime
            })
            .Top(top)
            .OrderBy("receivedDateTime desc")
            .GetAsync();
    
  • User Avatar
    0
    Bernard created

    Hi,

    The error message in logs has changed :

    IDW10502: An MsalUiRequiredException was thrown due to a challenge for the user. See https://aka.ms/ms-id-web/ca_incremental-consent.

  • User Avatar
    0
    Bernard created

    Hi

    I changed several things, but you solution for schemas is right.

    Now next steps for me is to solve this issue :

    Microsoft.Graph.ServiceException: Code: generalException Message: An error occurred sending the request.

    ---> Microsoft.Identity.Web.MicrosoftIdentityWebChallengeUserException: IDW10502: An MsalUiRequiredException was thrown due to a challenge for the user. See https://aka.ms/ms-id-web/ca_incremental-consent. ---> MSAL.NetCore.4.61.3.0.MsalUiRequiredException: ErrorCode: user_null Microsoft.Identity.Client.MsalUiRequiredException: No account or login hint was passed to the AcquireTokenSilent call.

    I trying diffetent Stackoverflow solution but no chances at the moment.

    Maybe a token refresh issue ? Any idea ?

    Thks for all.

  • User Avatar
    0
    m.aliozkaya created
    Support Team

    Hi @Bernard,

    Could you check https://stackoverflow.com/questions/73886403/idw10502-an-msaluirequiredexception-was-thrown-due-to-a-challenge-for-the-user