/
Program.cs
56 lines (41 loc) · 1.55 KB
/
Program.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
52
53
54
55
56
using System.Net;
using System.Net.Http.Headers;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapGet("/HelloWorld", () =>
{
return new string[] { "value", "someValue" };
});
app.MapPost("/token", async () =>
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
var url = new Uri("https://identity-dev.fortellis.io/oauth2/aus1ni5i9n9WkzcYa2p7/v1/token");
var handler = new HttpClientHandler();
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", "Basic {yourBase64EncodedAPIKey:APISecret}");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent data = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("scope", "anonymous"),
new KeyValuePair<string, string>("grant_type", "client_credentials")
});
Console.WriteLine($"This is what's in the data: {data.ToString}");
var res = await client.PostAsync(url, data);
var content = await res.Content.ReadAsStringAsync();
Console.WriteLine("This is the content of the response: " + content);
return content;
});
app.Run();