Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Invalid response Content-Type: text/html

I have implemented IdentityServer4 on an asp.net core 3.1 webapp I uploaded to an Azure App Service which is being consumed by an Angular 9 (using oidc-client 1.10.1) on another Azure App Service. When running these two on my local IIS 10.0 Web Server, everything works fine. On Azure, when calling UserManager.signinRedirect() in the the Angular 9 app, it responds the following error (I can see on the browser console):

Error: Uncaught (in promise): Error: Invalid response Content-Type: text/html, from URL: idpservername.azurewebsites.net/.well-known/openid-configuration
If I copy/paste the URL on the address bar of the browser it responds a valid json content.

I googled and found this link: https://github.com/IdentityServer/IdentityServer4/issues/2967 But it does not help much because the case is closed due to lack of activity where last answer reads "it turns out that IIS was not rendering html properly. I am running the IdentityServer on an App Service (I am not using a Virtual Machine), therefore, I don't have access to the IIS (if the answer implies configuring something directly on the IIS Web Server).

Do you have any suggestions on how to solve this problem? :-\

like image 647
Manuel Hernandez Avatar asked Feb 10 '26 23:02

Manuel Hernandez


1 Answers

Well, I resolved my issue! :)

The bug was located on my Angular code.

I had not correctly defined the URL string on the authority UserManager property. My incorrect code read as follows:

@Injectable()
export class AuthService {
   private _userManager = new UserManager({
      authority: 'idsdomain.azurewebsites.net/', 
      ...
   });
   ...
}

Notice the URL string value for the "authority" property is missing "https://" prefix. Uhg!!

I finally caught the error when carefully reading under the "Network" tab on "Google Developer tools" (press F12) the Request URL showing a wrong string and, I noticed the Response was also the full Index.cshtml page.

The correct code should read as follows:

@Injectable()
export class AuthService {
   private _userManager = new UserManager({
      authority: 'https://idsdomain.azurewebsites.net/', 
      ...
   });
   ...
}

Hopefully this helps anyone. Sometimes the simplest bugs are the hardest to get!

like image 94
Manuel Hernandez Avatar answered Feb 12 '26 14:02

Manuel Hernandez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!