IdentityServer8
This commit is contained in:
parent
18ddbead66
commit
a16188338a
47 changed files with 4077 additions and 529 deletions
|
|
@ -27,7 +27,7 @@ namespace Yavsc.Controllers
|
|||
[HttpGet]
|
||||
public IEnumerable<BlogPost> GetBlogspot()
|
||||
{
|
||||
return _context.Blogspot.Where(b => b.Visible).OrderByDescending(b => b.UserModified);
|
||||
return _context.BlogSpot.Where(b => b.Visible).OrderByDescending(b => b.UserModified);
|
||||
}
|
||||
|
||||
// GET: api/BlogApi/5
|
||||
|
|
@ -39,7 +39,7 @@ namespace Yavsc.Controllers
|
|||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
BlogPost blog = _context.BlogSpot.Single(m => m.Id == id);
|
||||
|
||||
if (blog == null)
|
||||
{
|
||||
|
|
@ -93,7 +93,7 @@ namespace Yavsc.Controllers
|
|||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
_context.Blogspot.Add(blog);
|
||||
_context.BlogSpot.Add(blog);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
|
@ -122,13 +122,13 @@ namespace Yavsc.Controllers
|
|||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id);
|
||||
BlogPost blog = _context.BlogSpot.Single(m => m.Id == id);
|
||||
if (blog == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
_context.Blogspot.Remove(blog);
|
||||
_context.BlogSpot.Remove(blog);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return Ok(blog);
|
||||
|
|
@ -145,7 +145,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
private bool BlogExists(long id)
|
||||
{
|
||||
return _context.Blogspot.Count(e => e.Id == id) > 0;
|
||||
return _context.BlogSpot.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
var article = await _context.Blogspot.FirstOrDefaultAsync
|
||||
var article = await _context.BlogSpot.FirstOrDefaultAsync
|
||||
(p=> p.Id == post.ReceiverId);
|
||||
|
||||
if (article==null) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Yavsc.Controllers
|
|||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
Models.Blog.BlogPost blogpost = _context.Blogspot.Single(x=>x.Id == id);
|
||||
Models.Blog.BlogPost blogpost = _context.BlogSpot.Single(x=>x.Id == id);
|
||||
|
||||
if (blogpost == null)
|
||||
{
|
||||
|
|
@ -39,7 +39,6 @@ namespace Yavsc.Controllers
|
|||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
return BadRequest();
|
||||
|
||||
blogpost.Rate = rate;
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return Ok();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Yavsc.Models.Account;
|
|||
using Yavsc.ViewModels.Account;
|
||||
using Yavsc.Helpers;
|
||||
using Yavsc.Abstract.Identity;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Yavsc.WebApi.Controllers
|
||||
{
|
||||
|
|
@ -129,7 +130,7 @@ namespace Yavsc.WebApi.Controllers
|
|||
return new BadRequestObjectResult(
|
||||
new { error = "user not found" });
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
|
||||
var uuid = User.GetUserId();
|
||||
var userData = await _dbContext.Users
|
||||
.Include(u=>u.PostalAddress)
|
||||
.Include(u=>u.AccountBalance)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer8;
|
||||
using IdentityServer8.Models;
|
||||
using Yavsc.Settings;
|
||||
|
||||
namespace Yavsc;
|
||||
|
|
@ -65,17 +66,20 @@ public static class Config
|
|||
// interactive client using code flow + pkce
|
||||
new Client
|
||||
{
|
||||
ClientId = "interactive",
|
||||
ClientId = "mvc",
|
||||
ClientSecrets = { new Secret("49C1A7E1-0C79-4A89-A3D6-A37998FB86B0".Sha256()) },
|
||||
|
||||
AllowedGrantTypes = GrantTypes.Code,
|
||||
|
||||
RedirectUris = { "https://localhost:5003/signin-oidc" },
|
||||
FrontChannelLogoutUri = "https://localhost:5003/signout-oidc",
|
||||
RedirectUris = { "https://localhost:5003/signin-oidc",
|
||||
"http://localhost:5002/signin-oidc" },
|
||||
PostLogoutRedirectUris = { "https://localhost:5003/signout-callback-oidc" },
|
||||
|
||||
AllowOfflineAccess = true,
|
||||
AllowedScopes = { "openid", "profile", "scope2" }
|
||||
AllowedScopes = {
|
||||
IdentityServerConstants.StandardScopes.OpenId,
|
||||
IdentityServerConstants.StandardScopes.Profile,
|
||||
"scope2" }
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,16 +13,16 @@ using Yavsc.ViewModels.Account;
|
|||
using Yavsc.Helpers;
|
||||
using Yavsc.Abstract.Manage;
|
||||
using Yavsc.Interface;
|
||||
using IdentityServer4.Test;
|
||||
using IdentityServer4.Services;
|
||||
using IdentityServer4.Stores;
|
||||
using IdentityServer8.Test;
|
||||
using IdentityServer8.Services;
|
||||
using IdentityServer8.Stores;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Yavsc.Models.Access;
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer8.Models;
|
||||
using Yavsc.Extensions;
|
||||
using IdentityServer4.Events;
|
||||
using IdentityServer4.Extensions;
|
||||
using IdentityServer4;
|
||||
using IdentityServer8.Events;
|
||||
using IdentityServer8.Extensions;
|
||||
using IdentityServer8;
|
||||
using IdentityModel;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.Unicode;
|
||||
|
|
@ -278,7 +278,7 @@ namespace Yavsc.Controllers
|
|||
var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
|
||||
if (context?.IdP != null && await _schemeProvider.GetSchemeAsync(context.IdP) != null)
|
||||
{
|
||||
var local = context.IdP == IdentityServer4.IdentityServerConstants.LocalIdentityProvider;
|
||||
var local = context.IdP == IdentityServer8.IdentityServerConstants.LocalIdentityProvider;
|
||||
|
||||
// this is meant to short circuit the UI and only trigger the one external IdP
|
||||
var vm = new LoginViewModel
|
||||
|
|
@ -380,7 +380,7 @@ namespace Yavsc.Controllers
|
|||
if (User?.Identity.IsAuthenticated == true)
|
||||
{
|
||||
var idp = User.FindFirst(JwtClaimTypes.IdentityProvider)?.Value;
|
||||
if (idp != null && idp != IdentityServer4.IdentityServerConstants.LocalIdentityProvider)
|
||||
if (idp != null && idp != IdentityServer8.IdentityServerConstants.LocalIdentityProvider)
|
||||
{
|
||||
var providerSupportsSignout = await HttpContext.GetSchemeSupportsSignOutAsync(idp);
|
||||
if (providerSupportsSignout)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
var user = await GetCurrentUserAsync();
|
||||
|
||||
long pc = _dbContext.Blogspot.Count(x => x.AuthorId == user.Id);
|
||||
long pc = _dbContext.BlogSpot.Count(x => x.AuthorId == user.Id);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
ViewData["Title"] = id;
|
||||
return View("Title", _context.Blogspot.Include(
|
||||
return View("Title", _context.BlogSpot.Include(
|
||||
b => b.Author
|
||||
).Where(x => x.Title == id && (x.Visible || x.AuthorId == uid )).OrderByDescending(
|
||||
x => x.DateCreated
|
||||
|
|
@ -78,7 +78,7 @@ namespace Yavsc.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
BlogPost blog = _context.Blogspot
|
||||
BlogPost blog = _context.BlogSpot
|
||||
.Include(p => p.Author)
|
||||
.Include(p => p.Tags)
|
||||
.Include(p => p.Comments)
|
||||
|
|
@ -128,10 +128,9 @@ namespace Yavsc.Controllers
|
|||
Title = blogInput.Title,
|
||||
Content = blogInput.Content,
|
||||
Photo = blogInput.Photo,
|
||||
Rate = 0,
|
||||
AuthorId = User.GetUserId()
|
||||
};
|
||||
_context.Blogspot.Add(post);
|
||||
_context.BlogSpot.Add(post);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
|
@ -150,7 +149,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
ViewData["PostTarget"]="Edit";
|
||||
BlogPost blog = _context.Blogspot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
||||
BlogPost blog = _context.BlogSpot.Include(x => x.Author).Include(x => x.ACL).Single(m => m.Id == id);
|
||||
|
||||
if (blog == null)
|
||||
{
|
||||
|
|
@ -212,7 +211,7 @@ namespace Yavsc.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
BlogPost blog = _context.Blogspot.Include(
|
||||
BlogPost blog = _context.BlogSpot.Include(
|
||||
b => b.Author
|
||||
).Single(m => m.Id == id);
|
||||
if (blog == null)
|
||||
|
|
@ -229,9 +228,9 @@ namespace Yavsc.Controllers
|
|||
public IActionResult DeleteConfirmed(long id)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
BlogPost blog = _context.Blogspot.Single(m => m.Id == id && m.AuthorId == uid );
|
||||
BlogPost blog = _context.BlogSpot.Single(m => m.Id == id && m.AuthorId == uid );
|
||||
|
||||
_context.Blogspot.Remove(blog);
|
||||
_context.BlogSpot.Remove(blog);
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
||||
return RedirectToAction("Index");
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace Yavsc.Controllers
|
|||
// GET: Comments/Create
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewData["ReceiverId"] = new SelectList(_context.Blogspot, "Id", "Post");
|
||||
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post");
|
||||
return View();
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ namespace Yavsc.Controllers
|
|||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
ViewData["ReceiverId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.ReceiverId);
|
||||
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
ViewData["ReceiverId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.ReceiverId);
|
||||
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ namespace Yavsc.Controllers
|
|||
await _context.SaveChangesAsync();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
ViewData["ReceiverId"] = new SelectList(_context.Blogspot, "Id", "Post", comment.ReceiverId);
|
||||
ViewData["ReceiverId"] = new SelectList(_context.BlogSpot, "Id", "Post", comment.ReceiverId);
|
||||
return View(comment);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
||||
|
||||
|
||||
using IdentityServer4.Events;
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer4.Services;
|
||||
using IdentityServer4.Extensions;
|
||||
using IdentityServer8.Events;
|
||||
using IdentityServer8.Models;
|
||||
using IdentityServer8.Services;
|
||||
using IdentityServer8.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityServer4.Validation;
|
||||
using IdentityServer8.Validation;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using Yavsc;
|
||||
|
|
@ -122,7 +122,7 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
var scopes = model.ScopesConsented;
|
||||
if (ConsentOptions.EnableOfflineAccess == false)
|
||||
{
|
||||
scopes = scopes.Where(x => x != IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess);
|
||||
scopes = scopes.Where(x => x != IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess);
|
||||
}
|
||||
|
||||
grantedConsent = new ConsentResponse
|
||||
|
|
@ -210,7 +210,7 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
}
|
||||
if (ConsentOptions.EnableOfflineAccess && request.ValidatedResources.Resources.OfflineAccess)
|
||||
{
|
||||
apiScopes.Add(GetOfflineAccessScope(vm.ScopesConsented.Contains(IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess) || model == null));
|
||||
apiScopes.Add(GetOfflineAccessScope(vm.ScopesConsented.Contains(IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess) || model == null));
|
||||
}
|
||||
vm.ApiScopes = apiScopes;
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ namespace IdentityServerHost.Quickstart.UI
|
|||
{
|
||||
return new ScopeViewModel
|
||||
{
|
||||
Value = IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess,
|
||||
Value = IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess,
|
||||
DisplayName = ConsentOptions.OfflineAccessDisplayName,
|
||||
Description = ConsentOptions.OfflineAccessDescription,
|
||||
Emphasize = true,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
||||
|
||||
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer8.Models;
|
||||
|
||||
namespace IdentityServerHost.Quickstart.UI
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using IdentityServer4.Configuration;
|
||||
using IdentityServer4.Events;
|
||||
using IdentityServer4.Extensions;
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer4.Services;
|
||||
using IdentityServer4.Validation;
|
||||
using IdentityServer8.Configuration;
|
||||
using IdentityServer8.Events;
|
||||
using IdentityServer8.Extensions;
|
||||
using IdentityServer8.Models;
|
||||
using IdentityServer8.Services;
|
||||
using IdentityServer8.Validation;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -103,7 +103,7 @@ namespace Yavsc.Controllers
|
|||
var scopes = model.ScopesConsented;
|
||||
if (ConsentOptions.EnableOfflineAccess == false)
|
||||
{
|
||||
scopes = scopes.Where(x => x != IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess);
|
||||
scopes = scopes.Where(x => x != IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess);
|
||||
}
|
||||
|
||||
grantedConsent = new ConsentResponse
|
||||
|
|
@ -185,7 +185,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
if (ConsentOptions.EnableOfflineAccess && request.ValidatedResources.Resources.OfflineAccess)
|
||||
{
|
||||
apiScopes.Add(GetOfflineAccessScope(vm.ScopesConsented.Contains(IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess) || model == null));
|
||||
apiScopes.Add(GetOfflineAccessScope(vm.ScopesConsented.Contains(IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess) || model == null));
|
||||
}
|
||||
vm.ApiScopes = apiScopes;
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return new ScopeViewModel
|
||||
{
|
||||
Value = IdentityServer4.IdentityServerConstants.StandardScopes.OfflineAccess,
|
||||
Value = IdentityServer8.IdentityServerConstants.StandardScopes.OfflineAccess,
|
||||
DisplayName = ConsentOptions.OfflineAccessDisplayName,
|
||||
Description = ConsentOptions.OfflineAccessDescription,
|
||||
Emphasize = true,
|
||||
|
|
|
|||
|
|
@ -2,15 +2,15 @@
|
|||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
||||
|
||||
|
||||
using IdentityServer4.Services;
|
||||
using IdentityServer4.Stores;
|
||||
using IdentityServer8.Services;
|
||||
using IdentityServer8.Stores;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IdentityServer4.Events;
|
||||
using IdentityServer4.Extensions;
|
||||
using IdentityServer8.Events;
|
||||
using IdentityServer8.Extensions;
|
||||
using Yavsc;
|
||||
using Yavsc.Models.Access;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ namespace Yavsc
|
|||
var result = context.Result;
|
||||
if (result is ViewResult)
|
||||
{
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
|
||||
#pragma warning disable ASP0019 // Suggest using IHeaderDictionary.Append or the indexer
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
|
||||
if (!context.HttpContext.Response.Headers.ContainsKey("X-Content-Type-Options"))
|
||||
{
|
||||
context.HttpContext.Response.Headers.Add("X-Content-Type-Options", "nosniff");
|
||||
|
|
@ -48,8 +49,10 @@ namespace Yavsc
|
|||
var referrer_policy = "no-referrer";
|
||||
if (!context.HttpContext.Response.Headers.ContainsKey("Referrer-Policy"))
|
||||
{
|
||||
context.HttpContext.Response.Headers.Add("Referrer-Policy", referrer_policy);
|
||||
context.HttpContext.Response.Headers.Add("Referrer-Policy", referrer_policy);
|
||||
}
|
||||
#pragma warning restore ASP0019 // Suggest using IHeaderDictionary.Append or the indexer
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Yavsc.Extensions {
|
||||
public static class AppBuilderExtensions {
|
||||
public static IApplicationBuilder UseWhen(this IApplicationBuilder app,
|
||||
Func<HttpContext, bool> condition, Action<IApplicationBuilder> configuration) {
|
||||
if (app == null) {
|
||||
throw new ArgumentNullException(nameof(app));
|
||||
}
|
||||
|
||||
if (condition == null) {
|
||||
throw new ArgumentNullException(nameof(condition));
|
||||
}
|
||||
|
||||
if (configuration == null) {
|
||||
throw new ArgumentNullException(nameof(configuration));
|
||||
}
|
||||
|
||||
var builder = app.New();
|
||||
configuration(builder);
|
||||
|
||||
return app.Use(next => {
|
||||
builder.Run(next);
|
||||
|
||||
var branch = builder.Build();
|
||||
|
||||
return context => {
|
||||
if (condition(context)) {
|
||||
return branch(context);
|
||||
}
|
||||
|
||||
return next(context);
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
using IdentityServer4.Models;
|
||||
using IdentityServer8.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yavsc.Models.Access;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Globalization;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Google.Apis.Util.Store;
|
||||
using IdentityServer4;
|
||||
using IdentityServer8;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
|
|
@ -12,6 +13,7 @@ using Microsoft.EntityFrameworkCore;
|
|||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Abstract.Workflow;
|
||||
|
|
@ -31,136 +33,136 @@ namespace Yavsc.Extensions;
|
|||
|
||||
internal static class HostingExtensions
|
||||
{
|
||||
public static IApplicationBuilder ConfigureFileServerApp(this IApplicationBuilder app,
|
||||
bool enableDirectoryBrowsing = false)
|
||||
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 userFilesDirInfo = new DirectoryInfo(Config.SiteSetup.Blog);
|
||||
AbstractFileSystemHelpers.UserFilesDirName = userFilesDirInfo.FullName;
|
||||
var avatarsDirInfo = new DirectoryInfo(Config.SiteSetup.Avatars);
|
||||
if (!avatarsDirInfo.Exists) avatarsDirInfo.Create();
|
||||
Config.AvatarsDirName = avatarsDirInfo.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
|
||||
};
|
||||
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;
|
||||
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.UserFilesOptions);
|
||||
|
||||
app.UseFileServer(Config.AvatarsOptions);
|
||||
|
||||
app.UseFileServer(Config.GitOptions);
|
||||
app.UseStaticFiles();
|
||||
return app;
|
||||
}
|
||||
app.UseFileServer(Config.AvatarsOptions);
|
||||
|
||||
app.UseFileServer(Config.GitOptions);
|
||||
app.UseStaticFiles();
|
||||
return app;
|
||||
}
|
||||
public static void ConfigureWorkflow()
|
||||
{
|
||||
foreach (var a in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var a in System.AppDomain.CurrentDomain.GetAssemblies())
|
||||
foreach (var c in a.GetTypes())
|
||||
{
|
||||
foreach (var c in a.GetTypes())
|
||||
if (c.IsClass && !c.IsAbstract &&
|
||||
c.GetInterface("ISpecializationSettings") != null)
|
||||
{
|
||||
if (c.IsClass && !c.IsAbstract &&
|
||||
c.GetInterface("ISpecializationSettings") != null)
|
||||
{
|
||||
Config.ProfileTypes.Add(c);
|
||||
}
|
||||
Config.ProfileTypes.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var propertyInfo in typeof(ApplicationDbContext).GetProperties())
|
||||
foreach (var propertyInfo in typeof(ApplicationDbContext).GetProperties())
|
||||
{
|
||||
foreach (var attr in propertyInfo.CustomAttributes)
|
||||
{
|
||||
foreach (var attr in propertyInfo.CustomAttributes)
|
||||
// something like a DbSet?
|
||||
if (typeof(Yavsc.Attributes.ActivitySettingsAttribute).IsAssignableFrom(attr.AttributeType))
|
||||
{
|
||||
// something like a DbSet?
|
||||
if (typeof(Yavsc.Attributes.ActivitySettingsAttribute).IsAssignableFrom(attr.AttributeType))
|
||||
{
|
||||
BillingService.UserSettings.Add(propertyInfo);
|
||||
}
|
||||
BillingService.UserSettings.Add(propertyInfo);
|
||||
}
|
||||
}
|
||||
|
||||
RegisterBilling<HairCutQuery>(BillingCodes.Brush, new Func<ApplicationDbContext,long,IDecidableQuery>
|
||||
( ( db, id) =>
|
||||
{
|
||||
var query = db.HairCutQueries.Include(q=>q.Prestation).Include(q=>q.Regularisation).Single(q=>q.Id == id) ;
|
||||
query.SelectedProfile = db.BrusherProfile.Single(b=>b.UserId == query.PerformerId);
|
||||
return query;
|
||||
})) ;
|
||||
|
||||
RegisterBilling<HairMultiCutQuery>(BillingCodes.MBrush,new Func<ApplicationDbContext,long,IDecidableQuery>
|
||||
( (db, id) => db.HairMultiCutQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id)));
|
||||
|
||||
RegisterBilling<RdvQuery>(BillingCodes.Rdv, new Func<ApplicationDbContext,long,IDecidableQuery>
|
||||
( (db, id) => db.RdvQueries.Include(q=>q.Regularisation).Single(q=>q.Id == id)));
|
||||
}
|
||||
public static void RegisterBilling<T>(string code, Func<ApplicationDbContext,long,IDecidableQuery> getter) where T : IBillable
|
||||
|
||||
RegisterBilling<HairCutQuery>(BillingCodes.Brush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) =>
|
||||
{
|
||||
BillingService.Billing.Add(code,getter) ;
|
||||
BillingService.GlobalBillingMap.Add(typeof(T).Name,code);
|
||||
}
|
||||
var query = db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id);
|
||||
query.SelectedProfile = db.BrusherProfile.Single(b => b.UserId == query.PerformerId);
|
||||
return query;
|
||||
}));
|
||||
|
||||
RegisterBilling<HairMultiCutQuery>(BillingCodes.MBrush, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.HairMultiCutQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
|
||||
RegisterBilling<RdvQuery>(BillingCodes.Rdv, new Func<ApplicationDbContext, long, IDecidableQuery>
|
||||
((db, id) => db.RdvQueries.Include(q => q.Regularisation).Single(q => q.Id == id)));
|
||||
}
|
||||
public static void RegisterBilling<T>(string code, Func<ApplicationDbContext, long, IDecidableQuery> getter) where T : IBillable
|
||||
{
|
||||
BillingService.Billing.Add(code, getter);
|
||||
BillingService.GlobalBillingMap.Add(typeof(T).Name, code);
|
||||
}
|
||||
|
||||
public static WebApplication ConfigureServices(this WebApplicationBuilder builder)
|
||||
{
|
||||
|
||||
|
||||
var siteSection = builder.Configuration.GetSection("Site");
|
||||
var smtpSection = builder.Configuration.GetSection("Smtp");
|
||||
var paypalSection = builder.Configuration.GetSection("Authentication:PayPal");
|
||||
// OAuth2AppSettings
|
||||
var googleAuthSettings = builder.Configuration.GetSection("Authentication:Google");
|
||||
|
||||
string? googleClientFile = builder.Configuration["Authentication:Google:GoogleWebClientJson"];
|
||||
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());
|
||||
}
|
||||
string? googleClientId = builder.Configuration["Authentication:Google:ClientId"];
|
||||
string? googleClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
|
||||
var siteSection = builder.Configuration.GetSection("Site");
|
||||
var smtpSection = builder.Configuration.GetSection("Smtp");
|
||||
var paypalSection = builder.Configuration.GetSection("Authentication:PayPal");
|
||||
// OAuth2AppSettings
|
||||
var googleAuthSettings = builder.Configuration.GetSection("Authentication:Google");
|
||||
|
||||
string? googleClientFile = builder.Configuration["Authentication:Google:GoogleWebClientJson"];
|
||||
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());
|
||||
}
|
||||
string? googleClientId = builder.Configuration["Authentication:Google:ClientId"];
|
||||
string? googleClientSecret = builder.Configuration["Authentication:Google:ClientSecret"];
|
||||
var services = builder.Services;
|
||||
_ = services.AddControllersWithViews()
|
||||
.AddNewtonsoftJson();
|
||||
LoadGoogleConfig(builder.Configuration);
|
||||
|
||||
LoadGoogleConfig(builder.Configuration);
|
||||
|
||||
services.Configure<SiteSettings>(siteSection);
|
||||
services.Configure<SmtpSettings>(smtpSection);
|
||||
services.Configure<PayPalSettings>(paypalSection);
|
||||
services.Configure<GoogleAuthSettings>(googleAuthSettings);
|
||||
|
||||
|
||||
services.AddRazorPages();
|
||||
services.AddSignalR(o =>
|
||||
{
|
||||
|
|
@ -174,9 +176,8 @@ internal static class HostingExtensions
|
|||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
|
||||
|
||||
services.AddIdentityServer(options =>
|
||||
var identityServerBuilder = services.AddIdentityServer(options =>
|
||||
{
|
||||
options.Events.RaiseErrorEvents = true;
|
||||
options.Events.RaiseInformationEvents = true;
|
||||
|
|
@ -187,152 +188,165 @@ internal static class HostingExtensions
|
|||
options.EmitStaticAudienceClaim = true;
|
||||
})
|
||||
.AddInMemoryIdentityResources(Config.IdentityResources)
|
||||
.AddInMemoryApiScopes(Config.ApiScopes)
|
||||
.AddInMemoryClients(Config.Clients)
|
||||
.AddInMemoryApiScopes(Config.ApiScopes)
|
||||
.AddAspNetIdentity<ApplicationUser>()
|
||||
;
|
||||
|
||||
if (builder.Environment.IsDevelopment())
|
||||
{
|
||||
identityServerBuilder.AddDeveloperSigningCredential();
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = builder.Configuration["YOUR-KEY-NAME"];
|
||||
var pfxBytes = Convert.FromBase64String(key);
|
||||
var cert = new X509Certificate2(pfxBytes, (string)null, X509KeyStorageFlags.MachineKeySet);
|
||||
identityServerBuilder.AddSigningCredential(cert);
|
||||
}
|
||||
services.AddSession();
|
||||
|
||||
|
||||
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
|
||||
|
||||
|
||||
services.AddAuthentication()
|
||||
.AddGoogle(options =>
|
||||
{
|
||||
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
|
||||
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
|
||||
|
||||
// register your IdentityServer with Google at https://console.developers.google.com
|
||||
// enable the Google+ API
|
||||
// set the redirect URI to https://localhost:5001/signin-google
|
||||
options.ClientId = googleClientId;
|
||||
options.ClientSecret = googleClientSecret;
|
||||
});
|
||||
services.Configure<RequestLocalizationOptions>(options =>
|
||||
|
||||
var authenticationBuilder = services.AddAuthentication();
|
||||
authenticationBuilder.AddGoogle(options =>
|
||||
{
|
||||
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
|
||||
|
||||
// register your IdentityServer with Google at https://console.developers.google.com
|
||||
// enable the Google+ API
|
||||
// set the redirect URI to https://localhost:5001/signin-google
|
||||
options.ClientId = googleClientId;
|
||||
options.ClientSecret = googleClientSecret;
|
||||
});
|
||||
|
||||
services.Configure<RequestLocalizationOptions>(options =>
|
||||
{
|
||||
CultureInfo[] supportedCultures = new[]
|
||||
{
|
||||
CultureInfo[] supportedCultures = new[]
|
||||
{
|
||||
new CultureInfo("en"),
|
||||
new CultureInfo("fr"),
|
||||
new CultureInfo("pt")
|
||||
};
|
||||
};
|
||||
|
||||
CultureInfo[] supportedUICultures = new[]
|
||||
{
|
||||
CultureInfo[] supportedUICultures = new[]
|
||||
{
|
||||
new CultureInfo("fr"),
|
||||
new CultureInfo("en"),
|
||||
new CultureInfo("pt")
|
||||
};
|
||||
};
|
||||
|
||||
// You must explicitly state which cultures your application supports.
|
||||
// These are the cultures the app supports for formatting numbers, dates, etc.
|
||||
options.SupportedCultures = supportedCultures;
|
||||
// You must explicitly state which cultures your application supports.
|
||||
// These are the cultures the app supports for formatting numbers, dates, etc.
|
||||
options.SupportedCultures = supportedCultures;
|
||||
|
||||
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
|
||||
options.SupportedUICultures = supportedUICultures;
|
||||
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
|
||||
options.SupportedUICultures = supportedUICultures;
|
||||
|
||||
options.RequestCultureProviders = new List<IRequestCultureProvider>
|
||||
{
|
||||
options.RequestCultureProviders = new List<IRequestCultureProvider>
|
||||
{
|
||||
new QueryStringRequestCultureProvider { Options = options },
|
||||
new CookieRequestCultureProvider { Options = options, CookieName="ASPNET_CULTURE" },
|
||||
new AcceptLanguageHeaderRequestCultureProvider { Options = options }
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("CorsPolicy", builder =>
|
||||
{
|
||||
_ = builder.WithOrigins("*");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Add the system clock service
|
||||
_ = services.AddSingleton<ISystemClock, SystemClock>();
|
||||
|
||||
_ = services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
||||
_ = services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
||||
_ = services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
||||
|
||||
services.AddMvc(config =>
|
||||
{
|
||||
/* var policy = new AuthorizationPolicyBuilder()
|
||||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
config.Filters.Add(new AuthorizeFilter(policy)); */
|
||||
config.Filters.Add(new ProducesAttribute("application/json"));
|
||||
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
|
||||
// config.ModelBinders.Insert(0,new MyDecimalModelBinder());
|
||||
config.EnableEndpointRouting = true;
|
||||
}).AddFormatterMappings(
|
||||
config => config.SetMediaTypeMappingForFormat("text/pdf",
|
||||
new MediaTypeHeaderValue("text/pdf"))
|
||||
).AddFormatterMappings(
|
||||
config => config.SetMediaTypeMappingForFormat("text/x-tex",
|
||||
new MediaTypeHeaderValue("text/x-tex"))
|
||||
)
|
||||
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
|
||||
options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
}).AddDataAnnotationsLocalization();
|
||||
|
||||
|
||||
_ = services.AddTransient<ITrueEmailSender, MailSender>();
|
||||
_ = services.AddTransient<Microsoft.AspNetCore.Identity.UI.Services.IEmailSender, MailSender>();
|
||||
_ = services.AddTransient<IYavscMessageSender, YavscMessageSender>();
|
||||
_ = services.AddTransient<IBillingService, BillingService>();
|
||||
_ = services.AddTransient<IDataStore, FileDataStore>((sp) => new FileDataStore("googledatastore", false));
|
||||
_ = services.AddTransient<ICalendarManager, CalendarManager>();
|
||||
|
||||
|
||||
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
|
||||
|
||||
_ = services.AddLocalization(options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
var dataDir = new DirectoryInfo(builder.Configuration["Site:DataDir"]);
|
||||
// Add session related services.
|
||||
|
||||
services.AddDataProtection().PersistKeysToFileSystem(dataDir);
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
|
||||
options.AddPolicy("AdministratorOnly", policy =>
|
||||
{
|
||||
_ = policy.RequireClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", Constants.AdminGroupName);
|
||||
});
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("CorsPolicy", builder =>
|
||||
{
|
||||
_ = builder.WithOrigins("*");
|
||||
});
|
||||
});
|
||||
options.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName));
|
||||
options.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
|
||||
.AddAuthenticationSchemes("Bearer")
|
||||
.RequireAuthenticatedUser().Build());
|
||||
// options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
|
||||
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
|
||||
options.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
|
||||
options.AddPolicy("IsTheAuthor", policy =>
|
||||
policy.Requirements.Add(new EditPermission()));
|
||||
});
|
||||
|
||||
services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
||||
|
||||
|
||||
// Add the system clock service
|
||||
_ = services.AddSingleton<ISystemClock, SystemClock>();
|
||||
|
||||
_ = services.AddSingleton<IConnexionManager, HubConnectionManager>();
|
||||
_ = services.AddSingleton<ILiveProcessor, LiveProcessor>();
|
||||
_ = services.AddTransient<IFileSystemAuthManager, FileSystemAuthManager>();
|
||||
|
||||
services.AddMvc(config =>
|
||||
{
|
||||
/* var policy = new AuthorizationPolicyBuilder()
|
||||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
config.Filters.Add(new AuthorizeFilter(policy)); */
|
||||
config.Filters.Add(new ProducesAttribute("application/json"));
|
||||
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
|
||||
// config.ModelBinders.Insert(0,new MyDecimalModelBinder());
|
||||
config.EnableEndpointRouting = true;
|
||||
}).AddFormatterMappings(
|
||||
config => config.SetMediaTypeMappingForFormat("text/pdf",
|
||||
new MediaTypeHeaderValue("text/pdf"))
|
||||
).AddFormatterMappings(
|
||||
config => config.SetMediaTypeMappingForFormat("text/x-tex",
|
||||
new MediaTypeHeaderValue("text/x-tex"))
|
||||
)
|
||||
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix,
|
||||
options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
}).AddDataAnnotationsLocalization();
|
||||
|
||||
|
||||
_ = services.AddTransient<ITrueEmailSender, MailSender>();
|
||||
_ = services.AddTransient<Microsoft.AspNetCore.Identity.UI.Services.IEmailSender, MailSender>();
|
||||
_ = services.AddTransient<IYavscMessageSender, YavscMessageSender>();
|
||||
_ = services.AddTransient<IBillingService, BillingService>();
|
||||
_ = services.AddTransient<IDataStore, FileDataStore>((sp) => new FileDataStore("googledatastore", false));
|
||||
_ = services.AddTransient<ICalendarManager, CalendarManager>();
|
||||
|
||||
|
||||
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
|
||||
|
||||
_ = services.AddLocalization(options =>
|
||||
{
|
||||
options.ResourcesPath = "Resources";
|
||||
});
|
||||
var dataDir = new DirectoryInfo(builder.Configuration["Site:DataDir"]);
|
||||
// Add session related services.
|
||||
|
||||
services.AddDataProtection().PersistKeysToFileSystem(dataDir);
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
|
||||
options.AddPolicy("AdministratorOnly", policy =>
|
||||
{
|
||||
_ = policy.RequireClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role", Constants.AdminGroupName);
|
||||
});
|
||||
|
||||
options.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName));
|
||||
options.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
|
||||
.AddAuthenticationSchemes("Bearer")
|
||||
.RequireAuthenticatedUser().Build());
|
||||
// options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
|
||||
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
|
||||
options.AddPolicy("Authenticated", policy => policy.RequireAuthenticatedUser());
|
||||
options.AddPolicy("IsTheAuthor", policy =>
|
||||
policy.Requirements.Add(new EditPermission()));
|
||||
});
|
||||
|
||||
services.AddSingleton<IAuthorizationHandler, PermissionHandler>();
|
||||
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
public static WebApplication ConfigurePipeline(this WebApplication app)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseIdentityServer();
|
||||
|
|
@ -353,15 +367,15 @@ internal static class HostingExtensions
|
|||
var googleAuthSettings = services.GetRequiredService<IOptions<GoogleAuthSettings>>();
|
||||
var authorizationService = services.GetRequiredService<IAuthorizationService>();
|
||||
var localization = services.GetRequiredService<IStringLocalizer<YavscLocalization>>();
|
||||
Startup.Configure(app, siteSettings, smtpSettings, authorizationService,
|
||||
Startup.Configure(app, siteSettings, smtpSettings, authorizationService,
|
||||
payPalSettings, googleAuthSettings, localization, loggerFactory,
|
||||
app.Environment.EnvironmentName );
|
||||
app.Environment.EnvironmentName);
|
||||
app.ConfigureFileServerApp();
|
||||
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void LoadGoogleConfig(IConfigurationRoot configuration)
|
||||
static void LoadGoogleConfig(IConfigurationRoot configuration)
|
||||
{
|
||||
string? googleClientFile = configuration["Authentication:Google:GoogleWebClientJson"];
|
||||
string? googleServiceAccountJsonFile = configuration["Authentication:Google:GoogleServiceAccountJson"];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
using System.Security.Claims;
|
||||
using IdentityServer4;
|
||||
using IdentityServer8;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Yavsc.Helpers
|
|||
{
|
||||
if (readerId == null)
|
||||
{
|
||||
var userPosts = dbContext.Blogspot.Include(
|
||||
var userPosts = dbContext.BlogSpot.Include(
|
||||
b => b.Author
|
||||
).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray();
|
||||
return userPosts;
|
||||
|
|
@ -40,7 +40,7 @@ namespace Yavsc.Helpers
|
|||
dbContext.Circle.Include(c => c.Members)
|
||||
.Where(c => c.Members.Any(m => m.MemberId == readerId))
|
||||
.Select(c => c.Id).ToArray();
|
||||
return dbContext.Blogspot.Include(
|
||||
return dbContext.BlogSpot.Include(
|
||||
b => b.Author
|
||||
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
|
||||
(x.Visible &&
|
||||
|
|
|
|||
3513
src/Yavsc/Migrations/20250208001037_blogspotcase.Designer.cs
generated
Normal file
3513
src/Yavsc/Migrations/20250208001037_blogspotcase.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load diff
161
src/Yavsc/Migrations/20250208001037_blogspotcase.cs
Normal file
161
src/Yavsc/Migrations/20250208001037_blogspotcase.cs
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Yavsc.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class blogspotcase : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Blogspot_AspNetUsers_AuthorId",
|
||||
table: "Blogspot");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_BlogTag_Blogspot_PostId",
|
||||
table: "BlogTag");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_CircleAuthorizationToBlogPost_Blogspot_BlogPostId",
|
||||
table: "CircleAuthorizationToBlogPost");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comment_Blogspot_ReceiverId",
|
||||
table: "Comment");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_Blogspot",
|
||||
table: "Blogspot");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Rate",
|
||||
table: "Blogspot");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "Blogspot",
|
||||
newName: "BlogSpot");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_Blogspot_AuthorId",
|
||||
table: "BlogSpot",
|
||||
newName: "IX_BlogSpot_AuthorId");
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_BlogSpot",
|
||||
table: "BlogSpot",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_BlogSpot_AspNetUsers_AuthorId",
|
||||
table: "BlogSpot",
|
||||
column: "AuthorId",
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_BlogTag_BlogSpot_PostId",
|
||||
table: "BlogTag",
|
||||
column: "PostId",
|
||||
principalTable: "BlogSpot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_CircleAuthorizationToBlogPost_BlogSpot_BlogPostId",
|
||||
table: "CircleAuthorizationToBlogPost",
|
||||
column: "BlogPostId",
|
||||
principalTable: "BlogSpot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comment_BlogSpot_ReceiverId",
|
||||
table: "Comment",
|
||||
column: "ReceiverId",
|
||||
principalTable: "BlogSpot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_BlogSpot_AspNetUsers_AuthorId",
|
||||
table: "BlogSpot");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_BlogTag_BlogSpot_PostId",
|
||||
table: "BlogTag");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_CircleAuthorizationToBlogPost_BlogSpot_BlogPostId",
|
||||
table: "CircleAuthorizationToBlogPost");
|
||||
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Comment_BlogSpot_ReceiverId",
|
||||
table: "Comment");
|
||||
|
||||
migrationBuilder.DropPrimaryKey(
|
||||
name: "PK_BlogSpot",
|
||||
table: "BlogSpot");
|
||||
|
||||
migrationBuilder.RenameTable(
|
||||
name: "BlogSpot",
|
||||
newName: "Blogspot");
|
||||
|
||||
migrationBuilder.RenameIndex(
|
||||
name: "IX_BlogSpot_AuthorId",
|
||||
table: "Blogspot",
|
||||
newName: "IX_Blogspot_AuthorId");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "Rate",
|
||||
table: "Blogspot",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddPrimaryKey(
|
||||
name: "PK_Blogspot",
|
||||
table: "Blogspot",
|
||||
column: "Id");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Blogspot_AspNetUsers_AuthorId",
|
||||
table: "Blogspot",
|
||||
column: "AuthorId",
|
||||
principalTable: "AspNetUsers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_BlogTag_Blogspot_PostId",
|
||||
table: "BlogTag",
|
||||
column: "PostId",
|
||||
principalTable: "Blogspot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_CircleAuthorizationToBlogPost_Blogspot_BlogPostId",
|
||||
table: "CircleAuthorizationToBlogPost",
|
||||
column: "BlogPostId",
|
||||
principalTable: "Blogspot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Comment_Blogspot_ReceiverId",
|
||||
table: "Comment",
|
||||
column: "ReceiverId",
|
||||
principalTable: "Blogspot",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -725,9 +725,6 @@ namespace Yavsc.Migrations
|
|||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)");
|
||||
|
||||
b.Property<int>("Rate")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(1024)
|
||||
|
|
@ -748,7 +745,7 @@ namespace Yavsc.Migrations
|
|||
|
||||
b.HasIndex("AuthorId");
|
||||
|
||||
b.ToTable("Blogspot");
|
||||
b.ToTable("BlogSpot");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Yavsc.Models.Blog.BlogTag", b =>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
||||
|
||||
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer8.Models;
|
||||
|
||||
namespace Yavsc.Models.Access
|
||||
{
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ namespace Yavsc.Models
|
|||
/// Users posts
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DbSet<Blog.BlogPost> Blogspot { get; set; }
|
||||
public DbSet<Blog.BlogPost> BlogSpot { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Skills powered by this site
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Yavsc
|
|||
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var app = builder.ConfigureServices().ConfigurePipeline();
|
||||
app.UseSession();
|
||||
app.Run();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
using IdentityServer4.Models;
|
||||
using IdentityServer4.Stores;
|
||||
using IdentityServer8.Models;
|
||||
using IdentityServer8.Stores;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace Yavsc.ViewComponents
|
|||
Where(c=>c.Members.Any(m=>m.MemberId == viewerId))
|
||||
.Select(c=>c.Id).ToArrayAsync();
|
||||
|
||||
var allposts = _context.Blogspot
|
||||
var allposts = _context.BlogSpot
|
||||
.Include(b => b.Author)
|
||||
.Include(p=>p.ACL)
|
||||
.Include(p=>p.Tags)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Yavsc.ViewComponents
|
|||
{
|
||||
if (target!=null)
|
||||
{
|
||||
var oid = target.GetOwnerId();
|
||||
var oid = target.OwnerId;
|
||||
ViewBag.ACL = dbContext.Circle.Where(
|
||||
c=>c.OwnerId == oid)
|
||||
.Select(
|
||||
|
|
|
|||
|
|
@ -41,12 +41,6 @@
|
|||
<dd>
|
||||
@Html.DisplayFor(model => model.DateCreated)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Rate)
|
||||
</dt>
|
||||
<dd>
|
||||
@Html.DisplayFor(model => model.Rate)
|
||||
</dd>
|
||||
<dt>
|
||||
@Html.DisplayNameFor(model => model.Title)
|
||||
</dt>
|
||||
|
|
|
|||
|
|
@ -25,9 +25,6 @@
|
|||
<th>
|
||||
@Html.DisplayNameFor(model => model.UserModified)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Rate)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Title)
|
||||
</th>
|
||||
|
|
@ -57,9 +54,6 @@
|
|||
<td>
|
||||
@Html.DisplayFor(modelItem => item.UserModified)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Rate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Title)
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
@using System.Diagnostics
|
||||
|
||||
@{
|
||||
var version = FileVersionInfo.GetVersionInfo(typeof(IdentityServer4.Hosting.IdentityServerMiddleware).Assembly.Location).ProductVersion.Split('+').First();
|
||||
var version = FileVersionInfo.GetVersionInfo(typeof(IdentityServer8.Hosting.IdentityServerMiddleware).Assembly.Location).ProductVersion.Split('+').First();
|
||||
}
|
||||
|
||||
<div class="welcome-page">
|
||||
<h1>
|
||||
<img src="~/icon.jpg">
|
||||
Welcome to IdentityServer4
|
||||
Welcome to IdentityServer8
|
||||
<small class="text-muted">(version @version)</small>
|
||||
</h1>
|
||||
|
||||
|
|
@ -25,8 +25,8 @@
|
|||
</li>
|
||||
<li>
|
||||
Here are links to the
|
||||
<a href="https://github.com/identityserver/IdentityServer4">source code repository</a>,
|
||||
and <a href="https://github.com/IdentityServer/IdentityServer4/tree/main/samples">ready to use samples</a>.
|
||||
<a href="https://github.com/identityserver/IdentityServer8">source code repository</a>,
|
||||
and <a href="https://github.com/IdentityServer/IdentityServer8/tree/main/samples">ready to use samples</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ Hello !!!
|
|||
</li>
|
||||
<li>
|
||||
Here are links to the
|
||||
<a href="https://github.com/identityserver/IdentityServer4">source code repository</a>,
|
||||
and <a href="https://github.com/IdentityServer/IdentityServer4/tree/main/samples">ready to use samples</a>.
|
||||
<a href="https://github.com/identityserver/IdentityServer8">source code repository</a>,
|
||||
and <a href="https://github.com/IdentityServer/IdentityServer8/tree/main/samples">ready to use samples</a>.
|
||||
</li>
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -12,24 +12,25 @@
|
|||
<PackageReference Include="bootstrap" Version="5.3.3" >
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="IdentityServer4" Version="4.1.2" />
|
||||
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
|
||||
|
||||
<PackageReference Include="HigginsSoft.IdentityServer8" Version="8.0.4" />
|
||||
<PackageReference Include="HigginsSoft.IdentityServer8.AspNetIdentity" Version="8.0.4" />
|
||||
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.12">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.12">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.12" IncludeAssets="All" />
|
||||
<PackageReference Include="Google.Apis.Compute.v1" Version="1.54.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0" />
|
||||
|
|
@ -37,11 +38,10 @@
|
|||
<PackageReference Include="MimeKit" Version="4.3.0" />
|
||||
<PackageReference Include="pazof.rules" Version="1.1.3" />
|
||||
<PackageReference Include="RazorEngine.NetCore" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.2" IncludeAssets="All" />
|
||||
<PackageReference Include="AsciiDocNet" Version="1.0.0-alpha6" />
|
||||
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
"Title": "Yavsc",
|
||||
"Slogan": "Yavsc!",
|
||||
"StyleSheet": "/css/default.css",
|
||||
"Authority": "http://127.0.0.1:5000/",
|
||||
"Authority": "https://127.0.0.1:5001/",
|
||||
"Owner": {
|
||||
"Name": "[Site owner's name]",
|
||||
"EMail": "[Site owner's e-mail address]"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue