Last active
March 19, 2021 15:15
-
-
Save DhyanRathore/88d0d44db051928f80cbc5323d583454 to your computer and use it in GitHub Desktop.
Get ClaimsPrincipal as a Binding Parameter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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