Azure / Azure/azure-functions-host
Set ClaimsPrincipal in Custom Binding
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 36
Description
Hello,
How is it possible not to set ClaimsPrincipal for Azure Functions v2?
When used locally the AF host sets ClaimsPrincipal with default values, as described in #33
What I want to achieve is to set ClaimsPrincipal with my own values, that are parsed out of the token inside of Custom Binding:
```
public class Example
{
[FunctionName("Example")]
public async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestMessage req,
[FunctionToken("Manager", "Worker", "Owner")] FunctionTokenResult token,
ClaimsPrincipal principal,
ILogger log)
{
var identity = token.Principal.Claims.First(x => x.Type == ClaimTypes.NameIdentifier);
return await Handler.WrapAsync(token,async () =>
{
log.LogInformation("C# HTTP trigger function processed a request.");
return new OkObjectResult($"Hello, {token}");
});
}
}
```
Full example: [here](https://github.com/vitalybibikov/AzureExtensions.FunctionToken)
So, in the example above I have:
1. FunctionTokenResult token which contains Principal property that was set by me.
2. ClaimsPrincipal principal that is set by the environment and contains default instance for the host.
I'm trying to substitute that default ClaimsPrincipal somewhere inside of the custom binding and be able to inject my own ClaimsPrincipal instance across the app.
Though I'm able to set it like so:
`
Request.HttpContext.User = claimsPrincipal;
`
I believe it should be possible to substitute ClaimsPrincipal with the desired one for the request.
Contributor guide
Research direction
Start by tracing Azure Functions v2 custom binding behavior and how the ClaimsPrincipal parameter is populated; the issue names no repository files or tests. Compare that path with the shown Request.HttpContext.User assignment. Done means establishing whether a custom binding can supply the request's ClaimsPrincipal and documenting or implementing the supported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- authentication, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100