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