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();