Finished adding user support and ability to update specific novels or set your last read chapter

This commit is contained in:
2022-07-17 20:34:06 -04:00
parent e4529e11c0
commit b5c4146d4d
34 changed files with 589 additions and 59 deletions

View File

@@ -0,0 +1,45 @@
using System.Security.Claims;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using WebNovelPortal.Authentication;
namespace Treestar.Shared.Authentication.OIDC;
public static class AuthenticationExtension
{
public static void AddOIDCAuth(this IServiceCollection services, IConfiguration configuration)
{
var oidcConfig = configuration.GetRequiredSection(OpenIdConnectAuthenticationOptions.ConfigurationSection)
.Get<OpenIdConnectAuthenticationOptions>();
services.AddAuthentication(opt =>
{
opt.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
opt.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(opt =>
{
opt.Authority = oidcConfig.Authority;
opt.ClientId = oidcConfig.ClientId;
opt.ClientSecret = oidcConfig.ClientSecret;
opt.ResponseType = OpenIdConnectResponseType.Code;
opt.GetClaimsFromUserInfoEndpoint = false;
opt.SaveTokens = true;
opt.UseTokenLifetime = true;
foreach (var scope in oidcConfig.Scopes.Split(" "))
{
opt.Scope.Add(scope);
}
opt.TokenValidationParameters = new TokenValidationParameters
{
NameClaimType = ClaimTypes.Name
};
});
}
}