/
CovenantUserController.cs
47 lines (42 loc) · 1.38 KB
/
CovenantUserController.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
39
40
41
42
43
44
45
46
47
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Rest;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Covenant.Core;
using Covenant.API;
using Covenant.API.Models;
namespace Covenant.Controllers
{
[Authorize]
public class CovenantUserController : Controller
{
private readonly CovenantAPI _client;
public CovenantUserController(IConfiguration configuration)
{
X509Certificate2 covenantCert = new X509Certificate2(Common.CovenantPublicCertFile);
HttpClientHandler clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, errors) =>
{
return cert.GetCertHashString() == covenantCert.GetCertHashString();
}
};
_client = new CovenantAPI(
new Uri("https://localhost:7443"),
new TokenCredentials(configuration["CovenantToken"]),
clientHandler
);
}
// GET: /users/
public async Task<IActionResult> Index()
{
return View(await _client.ApiUsersGetAsync());
}
}
}