bring code in

This commit is contained in:
Frank
2021-06-06 13:59:32 -04:00
parent c5715ce384
commit c837fae21c
2 changed files with 8 additions and 30 deletions
+6 -14
View File
@@ -20,24 +20,16 @@ namespace demo.Function
ClaimsPrincipal principal) ClaimsPrincipal principal)
{ {
log.LogInformation("C# HTTP trigger function processed a request."); log.LogInformation("C# HTTP trigger function processed a request.");
bool isClaimValid = true;
string userId = string.Empty;
if (principal == null) string name = req.Query["name"];
{
log.LogWarning("No principal.");
isClaimValid = false;
}
if(isClaimValid) string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
{ dynamic data = JsonConvert.DeserializeObject(requestBody);
userId = principal.FindFirst(ClaimTypes.GivenName).Value; name = name ?? data?.name;
log.LogInformation("Authenticated user {user}.", userId);
}
string responseMessage = string.IsNullOrEmpty(userId) string responseMessage = string.IsNullOrEmpty(name)
? "This SECURED HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." ? "This SECURED HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Bonjour Hi, {userId}. This SECURED HTTP triggered function executed successfully."; : $"Bonjour Hi, {name}. This SECURED HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage); return new OkObjectResult(responseMessage);
} }
-14
View File
@@ -20,20 +20,6 @@ namespace demo.Function
ClaimsPrincipal principal) ClaimsPrincipal principal)
{ {
log.LogInformation("C# HTTP trigger function processed a request."); log.LogInformation("C# HTTP trigger function processed a request.");
bool isClaimValid = true;
string userId = string.Empty;
if (principal == null)
{
log.LogWarning("No principal.");
isClaimValid = false;
}
if(isClaimValid)
{
userId = principal.FindFirst(ClaimTypes.GivenName).Value;
log.LogInformation("Authenticated user {user}.", userId);
}
string name = req.Query["name"]; string name = req.Query["name"];