Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
405 stars 167 forks source link

ClaimsPrincipal is null when StaticWebAppsAuthCookie is set. #789

Open pirovorster opened 2 years ago

pirovorster commented 2 years ago

I'm currently trying to get the ClaimsPrincipal from my isolated process Azure Function.

Initially I had the same issue as specified here: https://github.com/Azure/azure-functions-dotnet-worker/issues/694.

I upgraded to 1.6 and this fixed my claims being empty. However my ClaimsPrincipal is null.

I have the exact same function with the only difference being that its not a isolated process and the Claims Principal is NOT null. Initially I thought that once the claims got populated that the ClaimsPrincipal will magically work but this was not the case.

image

kshyju commented 2 years ago

You can access the ClaimsIdentity collection from the HttpRequestData instance.

IEnumerable<System.Security.Claims.ClaimsIdentity> identities = req.Identities;
pirovorster commented 2 years ago

The identities also does not have the identity from the "StaticWebAppsAuthCookie". Currently I con only get it by parsing the cookie myself. Imo it should work like the NON isolated process model.

pirovorster commented 2 years ago

This article illustrates a work around: https://adamstorr.azurewebsites.net/blog/using-azure-functions-middleware-to-access-claimsprincipal-in-azure-static-web-apps

brettsam commented 2 years ago

This seems like a good ask -- we'll assign it for investigation in a future sprint.