implemented Discord OAuth2
This commit is contained in:
parent
9365e22874
commit
dbf1be4c5d
18 changed files with 195 additions and 133 deletions
|
@ -1,4 +1,6 @@
|
|||
using Discord.OAuth2;
|
||||
using Lieb.Data;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
|
||||
|
@ -7,7 +9,20 @@ var builder = WebApplication.CreateBuilder(args);
|
|||
// Add services to the container.
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddServerSideBlazor();
|
||||
builder.Services.AddSingleton<WeatherForecastService>();
|
||||
builder.Services.AddAuthentication(opt =>
|
||||
{
|
||||
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
opt.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
|
||||
opt.DefaultChallengeScheme = DiscordDefaults.AuthenticationScheme;
|
||||
})
|
||||
.AddCookie()
|
||||
.AddDiscord(x =>
|
||||
{
|
||||
x.AppId = builder.Configuration["Discord:AppId"];
|
||||
x.AppSecret = builder.Configuration["Discord:AppSecret"];
|
||||
|
||||
x.SaveTokens = true;
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
@ -19,11 +34,18 @@ if (!app.Environment.IsDevelopment())
|
|||
app.UseHsts();
|
||||
}
|
||||
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
});
|
||||
|
||||
app.MapBlazorHub();
|
||||
app.MapFallbackToPage("/_Host");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue