config the issuer url
This commit is contained in:
@ -43,57 +43,6 @@ namespace Yavsc.Extensions;
|
|||||||
public static class HostingExtensions
|
public static class HostingExtensions
|
||||||
{
|
{
|
||||||
|
|
||||||
public static IApplicationBuilder ConfigureFileServerApp(this IApplicationBuilder app,
|
|
||||||
bool enableDirectoryBrowsing = false)
|
|
||||||
{
|
|
||||||
|
|
||||||
var userFilesDirInfo = new DirectoryInfo(Config.SiteSetup.Blog);
|
|
||||||
AbstractFileSystemHelpers.UserFilesDirName = userFilesDirInfo.FullName;
|
|
||||||
|
|
||||||
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
|
|
||||||
|
|
||||||
Config.UserFilesOptions = new FileServerOptions()
|
|
||||||
{
|
|
||||||
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
|
||||||
RequestPath = PathString.FromUriComponent(Constants.UserFilesPath),
|
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
|
||||||
};
|
|
||||||
Config.UserFilesOptions.EnableDefaultFiles = true;
|
|
||||||
Config.UserFilesOptions.StaticFileOptions.ServeUnknownFileTypes = true;
|
|
||||||
|
|
||||||
var avatarsDirInfo = new DirectoryInfo(Config.SiteSetup.Avatars);
|
|
||||||
if (!avatarsDirInfo.Exists) avatarsDirInfo.Create();
|
|
||||||
Config.AvatarsDirName = avatarsDirInfo.FullName;
|
|
||||||
|
|
||||||
Config.AvatarsOptions = new FileServerOptions()
|
|
||||||
{
|
|
||||||
FileProvider = new PhysicalFileProvider(Config.AvatarsDirName),
|
|
||||||
RequestPath = PathString.FromUriComponent(Constants.AvatarsPath),
|
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var gitdirinfo = new DirectoryInfo(Config.SiteSetup.GitRepository);
|
|
||||||
Config.GitDirName = gitdirinfo.FullName;
|
|
||||||
if (!gitdirinfo.Exists) gitdirinfo.Create();
|
|
||||||
Config.GitOptions = new FileServerOptions()
|
|
||||||
{
|
|
||||||
FileProvider = new PhysicalFileProvider(Config.GitDirName),
|
|
||||||
RequestPath = PathString.FromUriComponent(Constants.GitPath),
|
|
||||||
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
|
||||||
};
|
|
||||||
Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md");
|
|
||||||
Config.GitOptions.StaticFileOptions.ServeUnknownFileTypes = true;
|
|
||||||
|
|
||||||
app.UseFileServer(Config.UserFilesOptions);
|
|
||||||
|
|
||||||
app.UseFileServer(Config.AvatarsOptions);
|
|
||||||
|
|
||||||
app.UseFileServer(Config.GitOptions);
|
|
||||||
app.UseStaticFiles();
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static WebApplication ConfigureWebAppServices(this WebApplicationBuilder builder)
|
internal static WebApplication ConfigureWebAppServices(this WebApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
IServiceCollection services = LoadConfiguration(builder);
|
IServiceCollection services = LoadConfiguration(builder);
|
||||||
@ -231,23 +180,13 @@ public static class HostingExtensions
|
|||||||
// OAuth2AppSettings
|
// OAuth2AppSettings
|
||||||
var googleAuthSettings = builder.Configuration.GetSection("Authentication:Google");
|
var googleAuthSettings = builder.Configuration.GetSection("Authentication:Google");
|
||||||
|
|
||||||
string? googleClientFile = builder.Configuration["Authentication:Google:GoogleWebClientJson"];
|
//LoadGoogleConfig(builder.Configuration);
|
||||||
string? googleServiceAccountJsonFile = builder.Configuration["Authentication:Google:GoogleServiceAccountJson"];
|
|
||||||
if (googleClientFile != null)
|
|
||||||
{
|
|
||||||
Config.GoogleWebClientConfiguration = new ConfigurationBuilder().AddJsonFile(googleClientFile).Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (googleServiceAccountJsonFile != null)
|
|
||||||
{
|
|
||||||
FileInfo safile = new FileInfo(googleServiceAccountJsonFile);
|
|
||||||
Config.GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
|
|
||||||
}
|
|
||||||
var services = builder.Services;
|
var services = builder.Services;
|
||||||
_ = services.AddControllersWithViews()
|
_ = services.AddControllersWithViews()
|
||||||
.AddNewtonsoftJson();
|
.AddNewtonsoftJson();
|
||||||
LoadGoogleConfig(builder.Configuration);
|
|
||||||
|
|
||||||
services.Configure<SiteSettings>(siteSection);
|
services.Configure<SiteSettings>(siteSection);
|
||||||
services.Configure<SmtpSettings>(smtpSection);
|
services.Configure<SmtpSettings>(smtpSection);
|
||||||
services.Configure<PayPalSettings>(paypalSection);
|
services.Configure<PayPalSettings>(paypalSection);
|
||||||
@ -414,87 +353,57 @@ public static class HostingExtensions
|
|||||||
Config.GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
|
Config.GServiceAccount = JsonConvert.DeserializeObject<GoogleServiceAccount>(safile.OpenText().ReadToEnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public static IApplicationBuilder ConfigureFileServerApp(this IApplicationBuilder app,
|
||||||
public class MyIdentityStore : IUserClaimStore<IdentityUser>
|
bool enableDirectoryBrowsing = false)
|
||||||
{
|
{
|
||||||
public Task AddClaimsAsync(IdentityUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)
|
|
||||||
{
|
var userFilesDirInfo = new DirectoryInfo(Config.SiteSetup.Blog);
|
||||||
throw new NotImplementedException();
|
AbstractFileSystemHelpers.UserFilesDirName = userFilesDirInfo.FullName;
|
||||||
}
|
|
||||||
|
if (!userFilesDirInfo.Exists) userFilesDirInfo.Create();
|
||||||
public Task<IdentityResult> CreateAsync(IdentityUser user, CancellationToken cancellationToken)
|
|
||||||
{
|
Config.UserFilesOptions = new FileServerOptions()
|
||||||
throw new NotImplementedException();
|
{
|
||||||
}
|
FileProvider = new PhysicalFileProvider(AbstractFileSystemHelpers.UserFilesDirName),
|
||||||
|
RequestPath = PathString.FromUriComponent(Constants.UserFilesPath),
|
||||||
public Task<IdentityResult> DeleteAsync(IdentityUser user, CancellationToken cancellationToken)
|
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||||
{
|
};
|
||||||
throw new NotImplementedException();
|
Config.UserFilesOptions.EnableDefaultFiles = true;
|
||||||
}
|
Config.UserFilesOptions.StaticFileOptions.ServeUnknownFileTypes = true;
|
||||||
|
|
||||||
public void Dispose()
|
var avatarsDirInfo = new DirectoryInfo(Config.SiteSetup.Avatars);
|
||||||
{
|
if (!avatarsDirInfo.Exists) avatarsDirInfo.Create();
|
||||||
throw new NotImplementedException();
|
Config.AvatarsDirName = avatarsDirInfo.FullName;
|
||||||
}
|
|
||||||
|
Config.AvatarsOptions = new FileServerOptions()
|
||||||
public Task<IdentityUser?> FindByIdAsync(string userId, CancellationToken cancellationToken)
|
{
|
||||||
{
|
FileProvider = new PhysicalFileProvider(Config.AvatarsDirName),
|
||||||
throw new NotImplementedException();
|
RequestPath = PathString.FromUriComponent(Constants.AvatarsPath),
|
||||||
}
|
EnableDirectoryBrowsing = enableDirectoryBrowsing
|
||||||
|
};
|
||||||
public Task<IdentityUser?> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
var gitdirinfo = new DirectoryInfo(Config.SiteSetup.GitRepository);
|
||||||
}
|
Config.GitDirName = gitdirinfo.FullName;
|
||||||
|
if (!gitdirinfo.Exists) gitdirinfo.Create();
|
||||||
public Task<IList<Claim>> GetClaimsAsync(IdentityUser user, CancellationToken cancellationToken)
|
Config.GitOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
FileProvider = new PhysicalFileProvider(Config.GitDirName),
|
||||||
}
|
RequestPath = PathString.FromUriComponent(Constants.GitPath),
|
||||||
|
EnableDirectoryBrowsing = enableDirectoryBrowsing,
|
||||||
public Task<string?> GetNormalizedUserNameAsync(IdentityUser user, CancellationToken cancellationToken)
|
};
|
||||||
{
|
Config.GitOptions.DefaultFilesOptions.DefaultFileNames.Add("index.md");
|
||||||
throw new NotImplementedException();
|
Config.GitOptions.StaticFileOptions.ServeUnknownFileTypes = true;
|
||||||
}
|
|
||||||
|
app.UseFileServer(Config.UserFilesOptions);
|
||||||
public Task<string> GetUserIdAsync(IdentityUser user, CancellationToken cancellationToken)
|
|
||||||
{
|
app.UseFileServer(Config.AvatarsOptions);
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
app.UseFileServer(Config.GitOptions);
|
||||||
|
app.UseStaticFiles();
|
||||||
public Task<string?> GetUserNameAsync(IdentityUser user, CancellationToken cancellationToken)
|
return app;
|
||||||
{
|
}
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IList<IdentityUser>> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveClaimsAsync(IdentityUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task ReplaceClaimAsync(IdentityUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetNormalizedUserNameAsync(IdentityUser user, string? normalizedName, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task SetUserNameAsync(IdentityUser user, string? userName, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<IdentityResult> UpdateAsync(IdentityUser user, CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ namespace Yavsc.Helpers
|
|||||||
);
|
);
|
||||||
return googleLogin;
|
return googleLogin;
|
||||||
}
|
}
|
||||||
public static async Task<UserCredential> GetGoogleCredential(GoogleAuthSettings googleAuthSettings, IDataStore store, string googleUserLoginKey)
|
public static async Task<UserCredential> GetGoogleCredential(GoogleAuthSettings googleAuthSettings, IDataStore store, string googleUserLoginKey)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(googleUserLoginKey))
|
if (string.IsNullOrEmpty(googleUserLoginKey))
|
||||||
throw new InvalidOperationException("No Google login");
|
throw new InvalidOperationException("No Google login");
|
||||||
@ -82,7 +82,7 @@ namespace Yavsc.Helpers
|
|||||||
var token = await store.GetAsync<TokenResponse>(googleUserLoginKey);
|
var token = await store.GetAsync<TokenResponse>(googleUserLoginKey);
|
||||||
// token != null
|
// token != null
|
||||||
var c = SystemClock.Default;
|
var c = SystemClock.Default;
|
||||||
if (token.IsExpired(c)) {
|
if (token.IsStale) {
|
||||||
token = await RefreshToken(googleAuthSettings, token);
|
token = await RefreshToken(googleAuthSettings, token);
|
||||||
}
|
}
|
||||||
return new UserCredential(flow, googleUserLoginKey, token);
|
return new UserCredential(flow, googleUserLoginKey, token);
|
||||||
|
@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Authentication;
|
|||||||
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
|
JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
@ -28,8 +29,7 @@ builder.Services
|
|||||||
.AddCookie("Cookies")
|
.AddCookie("Cookies")
|
||||||
.AddOpenIdConnect("oidc", options =>
|
.AddOpenIdConnect("oidc", options =>
|
||||||
{
|
{
|
||||||
options.Authority = "https://localhost:5001";
|
options.Authority = builder.Configuration.GetValue<String>("AuthIssuer");
|
||||||
|
|
||||||
options.ClientId = "mvc";
|
options.ClientId = "mvc";
|
||||||
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";
|
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";
|
||||||
options.ResponseType = "code";
|
options.ResponseType = "code";
|
||||||
@ -47,6 +47,7 @@ builder.Services
|
|||||||
|
|
||||||
using (var app = builder.Build())
|
using (var app = builder.Build())
|
||||||
{
|
{
|
||||||
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
else
|
else
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
"AuthIssuer": "https://localhost:5001",
|
||||||
"Kestrel": {
|
"Kestrel": {
|
||||||
"Endpoints":
|
"Endpoints":
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user