Skip to content

Instantly share code, notes, and snippets.

@DhyanRathore
Last active March 19, 2021 15:15
Show Gist options
  • Save DhyanRathore/88d0d44db051928f80cbc5323d583454 to your computer and use it in GitHub Desktop.
Save DhyanRathore/88d0d44db051928f80cbc5323d583454 to your computer and use it in GitHub Desktop.
Get ClaimsPrincipal as a Binding Parameter
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Security.Claims;
// DEMO: Get ClaimsPrincipal as a binding parameter
namespace ClaimsDemo.Function
{
public static class ClaimsDemo
{
// Pass ClaimsPrincipal parameter in the function signature
[FunctionName("ClaimsDemo")]
public static IActionResult Run
([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]
HttpRequest req, ILogger log, ClaimsPrincipal claimIdentity)
{
log.LogInformation("User ID: " + claimIdentity.Identity.Name);
log.LogInformation("Claim Type : Claim Value");
foreach (Claim claim in claimIdentity.Claims)
{
log.LogInformation(claim.Type + " : " + claim.Value + "\n");
}
return new OkObjectResult("Success");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment