-
Notifications
You must be signed in to change notification settings - Fork 470
Open
Labels
Milestone
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<IActionResult> 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
So, in the example above I have:
- FunctionTokenResult token which contains Principal property that was set by me.
- 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.