-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTest.cs
38 lines (33 loc) · 1.29 KB
/
Test.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace PublicFunction
{
public class Test
{
[FunctionName("test")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log)
{
log.LogInformation("Starting function call");
var claims = req.HttpContext.User.Claims.ToList();
claims.ForEach(c => log.LogInformation($"{c.Type} - {c.Value} - {c.ValueType}"));
var roleClaim = claims.Single(c => c.Type == "roles");
log.LogInformation($"Role Claim: {roleClaim.Type} - {roleClaim.Value} - {roleClaim.ValueType}");
return new OkObjectResult(new TestResponse {
DateOfMessage = DateTime.Now,
Message = $"Hello from the Private Function! The APIM Managed Identity has been assigned to the role: {roleClaim.Value}"
});
}
}
}
public class TestResponse
{
public string Message { get; set; }
public DateTime DateOfMessage { get; set; }
}