0
votes

In a AzureAD authenticated app hosted in Azure i get the access token in the api controller like this

        public override void OnActionExecuting(ActionExecutingContext context)
    {
        base.OnActionExecuting(context);
        _client.DefaultRequestHeaders.Accept.Clear();

        var tokenHeader = Request.Headers["X-MS-TOKEN-ADD-ACCESS-TOKEN"];
        _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tokenHeader );
    }

Since Azure AD app service injects the token it works only when hosted in Azure.

How can i make it work in my development environment? This of course generates an exception.

Im following this tutorial: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-auth-aad#enable-authentication-and-authorization-for-back-end-app

Both backend and frontend are secured with AzureAD authentication. The frontend app has had permission set to the backend app in AzureAD section in the portal. In the code, there is nothing configured in appsettings.json.

1
Hi, Lautaro Are you using Easy Auth for this Web App? Or could you specify more details for your scenario. I'm not sure whether this case is linked the question you asked before.:-)Wayne Yang
Hi! Its not the same case as the last question. Im studying so i am just trying different stuff. Im not sure if im using Easy Auth but i added more info to the original question. Is that enough? also, thank you for your time!Daarwin
Well, You're using Easy Auth for your web App service. You know, Easy auth is for Azure Web App service, it's managed by Azure. So, I'm afraid of that you cannot use Easy Auth authentication for your app from your local machine.Wayne Yang

1 Answers

0
votes

According to your describe, you're using Easy Auth for your web App service. You know, Easy auth is for Azure Web App service, it's managed by Azure. So, I'm afraid of that you cannot use Easy Auth authentication for your app from your local machine.

For more detials about Easy Auth for Azure Web App service, you can refer to this documentation.

If you run the application locally on your development system, Easy Auth will not be available and you will not have the access tokens, etc. that you may need in your application. In order to debug those features of your application, you will need to deploy to an Azure Web App. An alternative approach is to do the login and authentication workflow in the application code, but then you are no longer leveraging Easy Auth.

However, there is a method to do Local Debugging of .NET Core Web App with Easy Auth.Here is a blog which introducts an approach to that. This blog may be helpful to give a thought for your scenario.