IHttpContextAccessor in Azure Function
- Dominant language
- PowerShell
- Stars
- 1.1k
- Forks
- 215
- Avg merge
- 4h 2m
- Merged PRs (30d)
- 1
Description
Hi,
It is not clear to me yet, if it's possible to use IHttpContextAccessor in an Azure Function's pipeline.
What I am doing right now:
1. Registering the IHttpContextAccessor as singleton in the IServiceCollection in azure function
2. In my library code I have a dependency on IHttpContextAccessor and use to access the current HttpContext.Request, so that I can set the Authorization header, something like this:
_httpContextAccessor.HttpContext.Request.Headers.Add("Authorization", "jwtToken_Value");
Then I need to read the token further down the line.
The issue that I've encountered is that between 2 requests to the azure function with 2 different jwtToken values, I find that my library code is **somehow saving and reading the first token it has from the first request.** ... I don't understand how / why it still has the old value, and let's say, if the HttpContext is the same between the requests, **that's fine** , but then **why** doesn't my azure function crash the second call when I am trying to add the second jwt token (after all it's a dictionary and if it still has the old value, then **why doesn't it crash** ? )
Overall it is still not clear to me if we're supposed to use IHttpContextAccessor and HttpContext in an azure function, or not.
Thanks
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the Azure Function IServiceCollection registration and the IHttpContextAccessor/HttpContext.Request usage described in the issue. Determine whether this access pattern is supported across function requests and document the request-lifetime behavior, including how Authorization headers should be handled without retaining an earlier token.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- backend, cloud
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100