Search code examples
azureactive-directoryasp.net-core-mvcazure-authentication

Register new application in Azure AD manually


I am using VS 2015 to create new web application (.NET core) with Azure AD authentication. After I run the app, I see that Azure AD automatically register the new app for me. Then I can login successfully with my Azure user.

But I want to register my app manually. Therefore I followed the instruction on this site: https://learn.microsoft.com/en-us/azure/active-directory/active-directory-app-registration

Then I register my new application manually on Azure AD, and then update generated client Id to my appsettings.json, and then run and login with Azure user. I got the error message:

An unhandled exception occurred while processing the request.

HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
MoveNext

AggregateException: Unhandled remote failure. (Response status code does not indicate success: 401 (Unauthorized).)
MoveNext

Can some experts let me know the reason? I am new to Azure. And one more question is I dont know why in my appsetting.json file there is no SecretKey?

This is the screen when I created the app

This is my appsetting.json file


Solution

  • This issue is caused the incorrect client secret for the app when you change the appsettings.json to the second app.

    The sensitive data are stored in a JSON configuration file in the user profile directory:

    Windows: %APPDATA%\microsoft\UserSecrets\\secrets.json

    Linux: ~/.microsoft/usersecrets//secrets.json

    Mac: ~/.microsoft/usersecrets//secrets.json

    After you chagne ClientSecret in the secrets.json, the app should works well.

    More detail about safe storage of app secrets during development, you can refer here.