0

I've got a small Blazor app that uses AzureAD for user authentication. When I run the app directly from visual studio, I am able to login without any issues, however when I deploy the app to IIS, I get the below error when I click 'Login'.

IOException: IDX20807: Unable to retrieve document from: 'System.String'. HttpResponseMessage: 
'System.Net.Http.HttpResponseMessage', HttpResponseMessage.Content: 'System.String'.
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, 
CancellationToken cancel)

InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
Microsoft.IdentityModel.Protocols.ConfigurationManager<T>.GetConfigurationAsync(CancellationToken cancel)

My appsettings.json configuration is:

AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "qualified.domain.name",
"TenantId": "22222222-2222-2222-2222-222222222222",
"ClientId": "11111111-1111-1111-11111111111111111",
"CallbackPath": "/signin-oidc",
"ClientSecret": "NNNNNNN-~nnnnnnnn_NNNNNNNNNNN~nnnn"
},

With the Domain, TenantId, ClientId and ClientSecret being populated from the secrets.json file.

My ConfigureServices function in the Startup.cs is:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
            .AddMicrosoftIdentityWebApp(Configuration.GetSection("AzureAd"))
            .EnableTokenAcquisitionToCallDownstreamApi(options =>
            {
                Configuration.Bind("AzureAd", options);
            }, GraphConstants.Scopes)
            .AddInMemoryTokenCaches();


        services.AddControllersWithViews()
            .AddMicrosoftIdentityUI();

        services.AddRazorPages();
        services.AddServerSideBlazor()
            .AddMicrosoftIdentityConsentHandler();
        services.AddMudServices();

     

    }

And the code for the Login button is:

<AuthorizeView>
<Authorized>
    Hello, @context.User.Identity.Name!
    <a href="MicrosoftIdentity/Account/SignOut">Log out</a>
</Authorized>
<NotAuthorized>
    <a href="MicrosoftIdentity/Account/SignIn">Log in</a>
</NotAuthorized>
</AuthorizeView>

My IIS configuration was done following the steps in this tutorial - https://www.c-sharpcorner.com/article/deploying-a-blazor-application-on-iis/

I've tried playing around with different settings around the AddMicrosoftIdentityWebApp section, figuring it was something to do with the configuration there, but nothing I try seems to make any difference.

Any help would be appreciated,

Thanks

  • Could you please check if [this post](https://github.com/AzureAD/microsoft-identity-web/issues/851) can help with your problem ? – Hury Shen Aug 13 '21 at 05:22

1 Answers1

1

Turns out the issue was to do with me using secrets.json to store some of the configuration.

This thread - ASP.NET Core 2 web application isn't loading user secrets when debugging IIS website - helped me figure out the solution