-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
103 lines (85 loc) · 3.15 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
using Swashbuckle.AspNetCore.SwaggerGen;
using TonProof;
using TonProof.Demo.Swagger;
using TonProof.Demo.Types;
using TonLibDotNet;
using TonLibDotNet.Types;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
builder.Services.Configure<SettingOptions>(
configuration.GetSection(SettingOptions.Tokens));
builder.Services.Configure<TonApiSettings>(
configuration.GetSection(TonApiSettings.TonApi));
builder.Services.Configure<TonOptions>(o =>
{
o.UseMainnet = false;
o.LogTextLimit = 500;
o.VerbosityLevel = 0;
o.Options.KeystoreType = new KeyStoreTypeDirectory("D:/Temp/keys");
});
builder.Services.Configure<TonProofOptions>(o =>
{
o.ValidAuthTime = 24 * 60 * 60 * 30;
o.AllowedDomains = ["winogarcia.github.io"];
});
var tonApiOptions = configuration.GetSection(TonApiSettings.TonApi).Get<TonApiSettings>();
builder.Services.AddHttpClient<IPublicKeyProvider, TonApiPublicKeyProvider>(
client =>
{
client.BaseAddress = new Uri(tonApiOptions.BaseAddress);
if (!string.IsNullOrEmpty(tonApiOptions.Token))
{
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {tonApiOptions.Token}");
}
}).AddStandardResilienceHandler();
//builder.Services.AddSingleton<IPublicKeyProvider, TonLibPublicKeyProvider>();
builder.Services.AddSwaggerGen();
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
// Add services to the container.
builder.Services.AddSingleton<ITonClient, TonClient>();
builder.Services.AddSingleton<ITonProofService, TonProofService>();
var settingOptions = configuration.GetSection(SettingOptions.Tokens).Get<SettingOptions>();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = settingOptions.Jwt.Issuer,
ValidAudience = settingOptions.Jwt.Audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(settingOptions.Jwt.SecretKey))
};
});
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(s =>
{
s.SwaggerEndpoint("/swagger/auth/swagger.json", "auth");
s.SwaggerEndpoint("/swagger/account/swagger.json", "account");
s.RoutePrefix = "swagger";
});
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.UseCors(
b => b
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
app.Run();