I'm working with .net 7 isolated azure function. before processing the business I need to add more information to the Claim Identity like the code below:
public async Task<IActionResult> PreprocessingRequestAsync(**HttpRequestData request**, Func<Task<IActionResult>> logic)
{
var hasId = request.Headers.TryGetValues("id", out var id);
var hasUsername = request.Headers.TryGetValues("username", out var username);
var hasEmail = request.Headers.TryGetValues("email", out var email);
if (hasId &&
hasUsername &&
hasEmail)
{
var user = new ClaimsIdentity(new[]
{
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
id.FirstOrDefault()),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname",
username.FirstOrDefault()),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
email.FirstOrDefault())
}
, "ByPassAuth");
**request.Identities.Append(user);**
var response = await ContinueToProcessBusinessLogicAsync(logic, request, false);
return response;
}
}
The above code was not able to work as expected (add more information to the Claim Identity). I know that Identities is ready-only property, but is there any way that allow me to do that.
Thank you,
You can setup your own Middleware that would push data to the
FunctionContext
.Now use your middleware in the
Program.cs
:And now access the
User
object in the Function: