mirror of
https://github.com/farcasclaudiu/AzureStaticWebApp-CSharp-SimpleDemo.git
synced 2026-06-22 05:01:01 +03:00
bring code in
This commit is contained in:
+7
-15
@@ -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);
|
||||
}
|
||||
|
||||
+1
-15
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user