I face difficulties to use Microsoft Entra External ID to authenticate a Blazor Web App

NIKOS EFENTAKIS 5 Reputation points
2025-02-22T17:49:43.8+00:00

I tried both example code: Azure-Samples/ ms-identity-ciam-dotnet-tutorial

and dotnet/ blazor-samples

I cannot run the samples in .Net 9.

I have managed to login succesfully (I get an annoying error message, but it does not throw an error: Could not read source map for https://aadcdn.msftauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js: Unexpected 404 response from https://aadcdn.msftauth.net/shared/1.0/content/js/oneDs_f2e0f4a029670f10d892.js.map:

BUT I cannot logout!

I place a link: <a href="MicrosoftIdentity/Account/SignOut">Logout</a>

and when I hit it I get the following exception:

TypeError: The provided value cannot be converted to a sequence.

Stack trace:

> at Object._oX (https://logincdn.msauth.net/16.000/content/js/MeControl_yl3C2NknpDMsGqlCvzLtmA2.js:1:15546)

> at https://logincdn.msauth.net/16.000/content/js/MeControl_yl3C2NknpDMsGqlCvzLtmA2.js:1:15195

I made the following adaptations:

  1. appsettings.json:
        "Domain": "azureefce.onmicrosoft.com",
    
        "TenantId": "a73...-54ff1faab232",
    
        "ClientId": "09e...1dab20",
    
        "CallbackPath": "/signin-oidc",
    
         "Instance": "https://a73...232.ciamlogin.com/",
    
        "ResponseType": "code"
    
  2. In App Registration I used mobile and desktop profile with url: https://localhost/signin-oidc

All other options failed (i.e. SPA or Web)

Can anyone help?

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
3,094 questions
{count} vote

3 answers

Sort by: Most helpful
  1. NIKOS EFENTAKIS 5 Reputation points
    2025-03-06T03:52:55.23+00:00

    Hello @SrideviM , thank you very much for your replies.

    The error shows up before the logout process. If I just stop debugging at this point, the user is not logged out.

    If I just press "Continue" in Visual Studio 2022, the program continues the execution and brings me to the logout page:

    User's image

    If I continue, logout process is performed correctly and the post logout direct Uri is hit correctly (actually It is redirected to the entry point of the site to reinitiate the login process-as I have programmed to login before rendering the first page), as defined in appSettings.json:

    User's image

    everything completes fine.


  2. NIKOS EFENTAKIS 5 Reputation points
    2025-03-06T04:10:48.8266667+00:00

    Another point.

    I had read the article you suggested above (https://learn.microsoft.com/en-us/aspnet/core/blazor/security/blazor-web-app-with-entra?view=aspnetcore-9.0#configure-the-app:%7E:text=https%3A//localhost/signout%2Dcallback%2Doidc)

    The suggested logout procedure is posting to authentication/logout by using the Layout/LogInOrOut.razor.

    My problem with this solution is that it does not work it directs to page: https://localhost:7285/authentication/logout, which isn't working (HTTP ERROR 405). But this might be my problem, as in the article it suggests that "The LogInOrOut component (Layout/LogInOrOut.razor) sets a hidden field for the return URL (ReturnUrl) to the current URL (currentURL)", which by directly navigating to ""MicrosoftIdentity/Account/SignOut"" might omit the ReturnUrl.

    0 comments No comments

  3. NIKOS EFENTAKIS 5 Reputation points
    2025-03-06T04:17:43.7233333+00:00

    I reread the MS Article. I noticed that suggests a specific method for logout (Layout/LogInOrOut.razor), which I couldn't implement. The reason is that when I click the submit button I am directed to page https://localhost:7285/authentication/logout, which is not working (HTTP ERROR 405).

    Initially I had implemented this suggestion, but when faced the 405 Error, I just searched for a workaround.

    Now I noticed that this method is suggested exactly for "The LogInOrOut component (Layout/LogInOrOut.razor) sets a hidden field for the return URL (ReturnUrl) to the current URL (currentURL).", which looks for the root of my problem, although injecting this ReturnUrl doesn't look to be necessary for the logout process.

    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.