forked from CodeBeamOrg/UltimateAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
134 lines (114 loc) · 4.03 KB
/
Program.cs
File metadata and controls
134 lines (114 loc) · 4.03 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using CodeBeam.UltimateAuth.Authorization.InMemory;
using CodeBeam.UltimateAuth.Authorization.InMemory.Extensions;
using CodeBeam.UltimateAuth.Authorization.Reference.Extensions;
using CodeBeam.UltimateAuth.Client.Extensions;
using CodeBeam.UltimateAuth.Core.Abstractions;
using CodeBeam.UltimateAuth.Core.Domain;
using CodeBeam.UltimateAuth.Core.Extensions;
using CodeBeam.UltimateAuth.Core.Infrastructure;
using CodeBeam.UltimateAuth.Core.MultiTenancy;
using CodeBeam.UltimateAuth.Credentials;
using CodeBeam.UltimateAuth.Credentials.InMemory.Extensions;
using CodeBeam.UltimateAuth.Credentials.Reference;
using CodeBeam.UltimateAuth.Sample.BlazorServer.Components;
using CodeBeam.UltimateAuth.Security.Argon2;
using CodeBeam.UltimateAuth.Server.Authentication;
using CodeBeam.UltimateAuth.Server.Defaults;
using CodeBeam.UltimateAuth.Server.Extensions;
using CodeBeam.UltimateAuth.Sessions.InMemory;
using CodeBeam.UltimateAuth.Tokens.InMemory;
using CodeBeam.UltimateAuth.Users.InMemory;
using CodeBeam.UltimateAuth.Users.InMemory.Extensions;
using CodeBeam.UltimateAuth.Users.Reference;
using CodeBeam.UltimateAuth.Users.Reference.Extensions;
using Microsoft.AspNetCore.Components;
using MudBlazor.Services;
using MudExtensions.Services;
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddCircuitOptions(options =>
{
options.DetailedErrors = true;
});
builder.Services.AddMudServices();
builder.Services.AddMudExtensions();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi();
builder.Services
.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = UAuthCookieDefaults.AuthenticationScheme;
options.DefaultSignInScheme = UAuthCookieDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = UAuthCookieDefaults.AuthenticationScheme;
})
.AddUAuthCookies();
builder.Services.AddAuthorization();
builder.Services.AddUltimateAuth();
builder.Services.AddUltimateAuthServer(o => {
o.Diagnostics.EnableRefreshHeaders = true;
//o.Session.MaxLifetime = TimeSpan.FromSeconds(32);
//o.Session.TouchInterval = TimeSpan.FromSeconds(9);
//o.Session.IdleTimeout = TimeSpan.FromSeconds(15);
})
.AddUltimateAuthUsersInMemory()
.AddUltimateAuthUsersReference()
.AddUltimateAuthCredentialsInMemory()
.AddUltimateAuthCredentialsReference()
.AddUltimateAuthAuthorizationInMemory()
.AddUltimateAuthAuthorizationReference()
.AddUltimateAuthInMemorySessions()
.AddUltimateAuthInMemoryTokens()
.AddUltimateAuthArgon2();
builder.Services.AddUltimateAuthClient(o =>
{
//o.Refresh.Interval = TimeSpan.FromSeconds(5);
o.Reauth.Behavior = ReauthBehavior.RaiseEvent;
});
builder.Services.AddScoped(sp =>
{
var navigation = sp.GetRequiredService<NavigationManager>();
return new HttpClient
{
BaseAddress = new Uri(navigation.BaseUri)
};
});
//builder.Services.AddHttpClient("AuthApi", client =>
//{
// client.BaseAddress = new Uri("https://localhost:7213");
//})
//.ConfigurePrimaryHttpMessageHandler(() =>
//{
// return new HttpClientHandler
// {
// UseCookies = true
// };
//});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
else
{
app.MapOpenApi();
app.MapScalarApiReference();
using var scope = app.Services.CreateScope();
var seedRunner = scope.ServiceProvider.GetRequiredService<SeedRunner>();
await seedRunner.RunAsync(null);
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseUltimateAuthServer();
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();
app.MapUAuthEndpoints();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();