From c837fae21c0e2a67c1d7e04f280807281043f64e Mon Sep 17 00:00:00 2001 From: Frank Date: Sun, 6 Jun 2021 13:59:32 -0400 Subject: [PATCH] bring code in --- api/HelloYou.cs | 22 +++++++--------------- api/JustHello.cs | 16 +--------------- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/api/HelloYou.cs b/api/HelloYou.cs index d9c7f13..918f801 100644 --- a/api/HelloYou.cs +++ b/api/HelloYou.cs @@ -20,24 +20,16 @@ namespace demo.Function ClaimsPrincipal principal) { log.LogInformation("C# HTTP trigger function processed a request."); - bool isClaimValid = true; - string userId = string.Empty; + + string name = req.Query["name"]; - if (principal == null) - { - log.LogWarning("No principal."); - isClaimValid = false; - } + string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); + dynamic data = JsonConvert.DeserializeObject(requestBody); + name = name ?? data?.name; - if(isClaimValid) - { - userId = principal.FindFirst(ClaimTypes.GivenName).Value; - 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." - : $"Bonjour Hi, {userId}. This SECURED HTTP triggered function executed successfully."; + : $"Bonjour Hi, {name}. This SECURED HTTP triggered function executed successfully."; return new OkObjectResult(responseMessage); } diff --git a/api/JustHello.cs b/api/JustHello.cs index 391ed84..869080d 100644 --- a/api/JustHello.cs +++ b/api/JustHello.cs @@ -20,21 +20,7 @@ namespace demo.Function ClaimsPrincipal principal) { 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 requestBody = await new StreamReader(req.Body).ReadToEndAsync();