-
Notifications
You must be signed in to change notification settings - Fork 275
Expand file tree
/
Copy pathProgram.cs
More file actions
99 lines (79 loc) · 3.09 KB
/
Program.cs
File metadata and controls
99 lines (79 loc) · 3.09 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
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using Duende.IdentityServer;
using IdentityServerHost;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.EntityFrameworkCore;
Console.Title = "IdentityServer";
var seed = args.Contains("/seed");
if (seed)
{
args = args.Except(new[] { "/seed" }).ToArray();
}
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddRazorPages();
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
if (seed)
{
Console.WriteLine("Seeding database...");
SeedData.EnsureSeedData(connectionString);
Console.WriteLine("Done seeding database.");
return;
}
builder.Services.AddIdentityServer(options =>
{
// see https://docs.duendesoftware.com/identityserver/fundamentals/resources
options.EmitStaticAudienceClaim = true;
// this controls how long the dynamic providers are cached, if caching is enabled (see AddConfigurationStoreCache() below)
options.Caching.IdentityProviderCacheDuration = TimeSpan.FromMinutes(15);
})
.AddTestUsers(TestUsers.Users)
// this adds the config data from DB (clients, resources, CORS)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlite(connectionString, dbOpts => dbOpts.MigrationsAssembly(typeof(Program).Assembly.FullName));
})
// this adds the operational data from DB (codes, tokens, consents)
.AddOperationalStore(options =>
{
options.ConfigureDbContext = b =>
b.UseSqlite(connectionString, dbOpts => dbOpts.MigrationsAssembly(typeof(Program).Assembly.FullName));
// this enables automatic token cleanup. this is optional.
options.EnableTokenCleanup = true;
})
// this enables caching for data loaded from the configuration store (including dynamic providers)
.AddConfigurationStoreCache();
builder.Services.AddAuthentication()
.AddOpenIdConnect("oidc", "Sign-in with demo.duendesoftware.com", options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.SignOutScheme = IdentityServerConstants.SignoutScheme;
options.SaveTokens = true;
options.Authority = "https://demo.duendesoftware.com";
options.ClientId = "interactive.confidential";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.TokenValidationParameters = new()
{
NameClaimType = "name",
RoleClaimType = "role"
};
});
// Add `.PersistKeysTo…()` and `.ProtectKeysWith…()` calls
// See more at https://docs.duendesoftware.com/general/data-protection
builder.Services.AddDataProtection()
.SetApplicationName("IdentityServer");
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();
app.UseAuthorization();
app.MapDefaultEndpoints();
app.MapRazorPages();
app.Run();