/
CredentialController.cs
51 lines (46 loc) · 1.75 KB
/
CredentialController.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
48
49
50
51
using System;
using System.Collections.Generic;
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.Extensions.Configuration;
using Covenant.Core;
using Covenant.API;
using Covenant.API.Models;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Covenant.Controllers
{
[Authorize]
public class CredentialController : Controller
{
private readonly CovenantAPI _client;
public CredentialController(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: /credential/
public async Task<IActionResult> Index()
{
ViewBag.PasswordCredentials = await _client.ApiCredentialsPasswordsGetAsync();
ViewBag.HashCredentials = await _client.ApiCredentialsHashesGetAsync();
ViewBag.TicketCredentials = await _client.ApiCredentialsTicketsGetAsync();
return View(await _client.ApiCredentialsGetAsync());
}
}
}