@ -1,6 +1,7 @@
using System.Globalization ;
using System.Globalization ;
using System.Security.Cryptography.X509Certificates ;
using Google.Apis.Util.Store ;
using Google.Apis.Util.Store ;
using IdentityServer 4 ;
using IdentityServer 8 ;
using Microsoft.AspNetCore.Authentication ;
using Microsoft.AspNetCore.Authentication ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.DataProtection ;
using Microsoft.AspNetCore.DataProtection ;
@ -12,6 +13,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders ;
using Microsoft.Extensions.FileProviders ;
using Microsoft.Extensions.Localization ;
using Microsoft.Extensions.Localization ;
using Microsoft.Extensions.Options ;
using Microsoft.Extensions.Options ;
using Microsoft.IdentityModel.Tokens ;
using Microsoft.Net.Http.Headers ;
using Microsoft.Net.Http.Headers ;
using Newtonsoft.Json ;
using Newtonsoft.Json ;
using Yavsc.Abstract.Workflow ;
using Yavsc.Abstract.Workflow ;
@ -31,136 +33,136 @@ namespace Yavsc.Extensions;
internal static class HostingExtensions
internal static class HostingExtensions
{
{
public static IApplicationBuilder ConfigureFileServerApp ( this IApplicationBuilder app ,
public static IApplicationBuilder ConfigureFileServerApp ( this IApplicationBuilder app ,
bool enableDirectoryBrowsing = false )
bool enableDirectoryBrowsing = false )
{
{
var userFilesDirInfo = new DirectoryInfo ( Config . SiteSetup . Blog ) ;
AbstractFileSystemHelpers . UserFilesDirName = userFilesDirInfo . FullName ;
if ( ! userFilesDirInfo . Exists ) userFilesDirInfo . Create ( ) ;
var userFilesDirInfo = new DirectoryInfo ( Config . SiteSetup . Blog ) ;
AbstractFileSystemHelpers . UserFilesDirName = userFilesDirInfo . FullName ;
Config . UserFilesOptions = new FileServerOptions ( )
if ( ! userFilesDirInfo . Exists ) userFilesDirInfo . Create ( ) ;
{
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 ) ;
Config . UserFilesOptions = new FileServerOptions ( )
if ( ! avatarsDirInfo . Exists ) avatarsDirInfo . Create ( ) ;
{
Config . AvatarsDirName = avatarsDirInfo . FullName ;
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 ) ;
app . UseFileServer ( Config . UserFilesOptions ) ;
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 . UserFile sOptions) ;
app . UseFileServer ( Config . AvatarsOptions ) ;
app . UseFileServer ( Config . AvatarsOptions ) ;
app . UseFileServer ( Config . GitOptions ) ;
app . UseStaticFiles ( ) ;
app . UseFileServer ( Config . GitOptions ) ;
return app ;
app . UseStaticFiles ( ) ;
}
return app ;
}
public static void ConfigureWorkflow ( )
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 . GetTyp es( ) )
{
{
foreach ( var c in a . GetTypes ( ) )
if ( c . IsClass & & ! c . IsAbstract & &
c . GetInterface ( "ISpecializationSettings" ) ! = null )
{
{
if ( c . IsClass & & ! c . IsAbstract & &
Config . ProfileTypes . Add ( c ) ;
c . GetInterface ( "ISpecializationSettings" ) ! = null )
{
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?
BillingService . UserSettings . Add ( propertyInfo ) ;
if ( typeof ( Yavsc . Attributes . ActivitySettingsAttribute ) . IsAssignableFrom ( attr . AttributeType ) )
{
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 ) ;
var query = db . HairCutQueries . Include ( q = > q . Prestation ) . Include ( q = > q . Regularisation ) . Single ( q = > q . Id = = id ) ;
BillingService . GlobalBillingMap . Add ( typeof ( T ) . Name , code ) ;
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 )
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 )
var siteSection = builder . Configuration . GetSection ( "Site" ) ;
{
var smtpSection = builder . Configuration . GetSection ( "Smtp" ) ;
FileInfo safile = new FileInfo ( googleServiceAccountJsonFile ) ;
var paypalSection = builder . Configuration . GetSection ( "Authentication:PayPal" ) ;
Config . GServiceAccount = JsonConvert . DeserializeObject < GoogleServiceAccount > ( safile . OpenText ( ) . ReadToEnd ( ) ) ;
// OAuth2AppSettings
}
var googleAuthSettings = builder . Configuration . GetSection ( "Authentication:Google" ) ;
string? googleClientId = builder . Configuration [ "Authentication:Google:ClientId" ] ;
string? googleClientSecret = builder . Configuration [ "Authentication:Google:ClientSecret" ] ;
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 ;
var services = builder . Services ;
_ = services . AddControllersWithViews ( )
_ = services . AddControllersWithViews ( )
. AddNewtonsoftJson ( ) ;
. AddNewtonsoftJson ( ) ;
LoadGoogleConfig ( builder . Configuration ) ;
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 ) ;
services . Configure < GoogleAuthSettings > ( googleAuthSettings ) ;
services . Configure < GoogleAuthSettings > ( googleAuthSettings ) ;
services . AddRazorPages ( ) ;
services . AddRazorPages ( ) ;
services . AddSignalR ( o = >
services . AddSignalR ( o = >
{
{
@ -174,9 +176,8 @@ internal static class HostingExtensions
. AddEntityFrameworkStores < ApplicationDbContext > ( )
. AddEntityFrameworkStores < ApplicationDbContext > ( )
. AddDefaultTokenProviders ( ) ;
. AddDefaultTokenProviders ( ) ;
services . AddIdentityServer ( options = >
var identityServerBuilder = services . AddIdentityServer ( options = >
{
{
options . Events . RaiseErrorEvents = true ;
options . Events . RaiseErrorEvents = true ;
options . Events . RaiseInformationEvents = true ;
options . Events . RaiseInformationEvents = true ;
@ -187,152 +188,165 @@ internal static class HostingExtensions
options . EmitStaticAudienceClaim = true ;
options . EmitStaticAudienceClaim = true ;
} )
} )
. AddInMemoryIdentityResources ( Config . IdentityResources )
. AddInMemoryIdentityResources ( Config . IdentityResources )
. AddInMemoryApiScopes ( Config . ApiScopes )
. AddInMemoryClients ( Config . Clients )
. AddInMemoryClients ( Config . Clients )
. AddInMemoryApiScopes ( Config . ApiScopes )
. AddAspNetIdentity < ApplicationUser > ( )
. 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 ( ) ;
services . AddSession ( ) ;
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
// TODO .AddServerSideSessionStore<YavscServerSideSessionStore>()
services . AddAuthentication ( )
. AddGoogle ( options = >
{
options . SignInScheme = IdentityServerConstants . ExternalCookieAuthenticationScheme ;
// register your IdentityServer with Google at https://console.developers.google.com
// enable the Google+ API
var authenticationBuilder = services . AddAuthentication ( ) ;
// set the redirect URI to https://localhost:5001/signin-google
authenticationBuilder . AddGoogle ( options = >
options . ClientId = googleClientId ;
{
options . ClientSecret = googleClientSecret ;
options . SignInScheme = IdentityServerConstants . ExternalCookieAuthenticationScheme ;
} ) ;
services . Configure < RequestLocalizationOptions > ( options = >
// 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 ( "en" ) ,
new CultureInfo ( "fr" ) ,
new CultureInfo ( "fr" ) ,
new CultureInfo ( "pt" )
new CultureInfo ( "pt" )
} ;
} ;
CultureInfo [ ] supportedUICultures = new [ ]
CultureInfo [ ] supportedUICultures = new [ ]
{
{
new CultureInfo ( "fr" ) ,
new CultureInfo ( "fr" ) ,
new CultureInfo ( "en" ) ,
new CultureInfo ( "en" ) ,
new CultureInfo ( "pt" )
new CultureInfo ( "pt" )
} ;
} ;
// You must explicitly state which cultures your application supports.
// You must explicitly state which cultures your application supports.
// These are the cultures the app supports for formatting numbers, dates, etc.
// These are the cultures the app supports for formatting numbers, dates, etc.
options . SupportedCultures = supportedCultures ;
options . SupportedCultures = supportedCultures ;
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
// These are the cultures the app supports for UI strings, i.e. we have localized resources for.
options . SupportedUICultures = supportedUICultures ;
options . SupportedUICultures = supportedUICultures ;
options . RequestCultureProviders = new List < IRequestCultureProvider >
options . RequestCultureProviders = new List < IRequestCultureProvider >
{
{
new QueryStringRequestCultureProvider { Options = options } ,
new QueryStringRequestCultureProvider { Options = options } ,
new CookieRequestCultureProvider { Options = options , CookieName = "ASPNET_CULTURE" } ,
new CookieRequestCultureProvider { Options = options , CookieName = "ASPNET_CULTURE" } ,
new AcceptLanguageHeaderRequestCultureProvider { Options = options }
new AcceptLanguageHeaderRequestCultureProvider { Options = options }
} ;
} ;
} ) ;
} ) ;
services . AddCors ( options = >
services . AddCors ( options = >
{
options . AddPolicy ( "CorsPolicy" , builder = >
{
{
options . AddPolicy ( "CorsPolicy" , builder = >
_ = builder . WithOrigins ( "*" ) ;
{
_ = builder . WithOrigins ( "*" ) ;
} ) ;
} ) ;
} ) ;
} ) ;
// Add the system clock service
// Add the system clock service
_ = services . AddSingleton < ISystemClock , SystemClock > ( ) ;
_ = services . AddSingleton < ISystemClock , SystemClock > ( ) ;
_ = services . AddSingleton < IConnexionManager , HubConnectionManager > ( ) ;
_ = services . AddSingleton < IConnexionManager , HubConnectionManager > ( ) ;
_ = services . AddSingleton < ILiveProcessor , LiveProcessor > ( ) ;
_ = services . AddSingleton < ILiveProcessor , LiveProcessor > ( ) ;
_ = services . AddTransient < IFileSystemAuthManager , FileSystemAuthManager > ( ) ;
_ = services . AddTransient < IFileSystemAuthManager , FileSystemAuthManager > ( ) ;
services . AddMvc ( config = >
services . AddMvc ( config = >
{
{
/ * var policy = new AuthorizationPolicyBuilder ( )
/ * var policy = new AuthorizationPolicyBuilder ( )
. RequireAuthenticatedUser ( )
. RequireAuthenticatedUser ( )
. Build ( ) ;
. Build ( ) ;
config . Filters . Add ( new AuthorizeFilter ( policy ) ) ; * /
config . Filters . Add ( new AuthorizeFilter ( policy ) ) ; * /
config . Filters . Add ( new ProducesAttribute ( "application/json" ) ) ;
config . Filters . Add ( new ProducesAttribute ( "application/json" ) ) ;
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
// config.ModelBinders.Insert(0,new MyDateTimeModelBinder());
// config.ModelBinders.Insert(0,new MyDecimalModelBinder());
// config.ModelBinders.Insert(0,new MyDecimalModelBinder());
config . EnableEndpointRouting = true ;
config . EnableEndpointRouting = true ;
} ) . AddFormatterMappings (
} ) . AddFormatterMappings (
config = > config . SetMediaTypeMappingForFormat ( "text/pdf" ,
config = > config . SetMediaTypeMappingForFormat ( "text/pdf" ,
new MediaTypeHeaderValue ( "text/pdf" ) )
new MediaTypeHeaderValue ( "text/pdf" ) )
) . AddFormatterMappings (
) . AddFormatterMappings (
config = > config . SetMediaTypeMappingForFormat ( "text/x-tex" ,
config = > config . SetMediaTypeMappingForFormat ( "text/x-tex" ,
new MediaTypeHeaderValue ( "text/x-tex" ) )
new MediaTypeHeaderValue ( "text/x-tex" ) )
)
)
. AddViewLocalization ( LanguageViewLocationExpanderFormat . Suffix ,
. AddViewLocalization ( LanguageViewLocationExpanderFormat . Suffix ,
options = >
options = >
{
{
options . ResourcesPath = "Resources" ;
options . ResourcesPath = "Resources" ;
} ) . AddDataAnnotationsLocalization ( ) ;
} ) . 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 > ( ) ;
_ = services . AddTransient < ITrueEmailSender , MailSender > ( ) ;
// TODO for SMS: services.AddTransient<ISmsSender, AuthMessageSender>();
_ = 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 . AddLocalization ( options = >
services . AddDataProtection ( ) . PersistKeysToFileSystem ( dataDir ) ;
services . AddAuthorization ( options = >
{
options . AddPolicy ( "AdministratorOnly" , policy = >
{
{
options . ResourcesPath = "Resources" ;
_ = policy . RequireClaim ( "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" , Constants . AdminGroupName ) ;
} ) ;
} ) ;
var dataDir = new DirectoryInfo ( builder . Configuration [ "Site:DataDir" ] ) ;
// Add session related services.
services . AddDataProtection ( ) . PersistKeysToFileSystem ( dataDir ) ;
services . AddAuthorization ( options = >
{
options . AddPolicy ( "AdministratorOnly" , policy = >
options . AddPolicy ( "FrontOffice" , policy = > policy . RequireRole ( Constants . FrontOfficeGroupName ) ) ;
{
options . AddPolicy ( "Bearer" , new AuthorizationPolicyBuilder ( )
_ = policy . RequireClaim ( "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" , Constants . AdminGroupName ) ;
. AddAuthenticationSchemes ( "Bearer" )
} ) ;
. RequireAuthenticatedUser ( ) . Build ( ) ) ;
// options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
options . AddPolicy ( "FrontOffice" , policy = > policy . RequireRole ( Constants . FrontOfficeGroupName ) ) ;
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
options . AddPolicy ( "Bearer" , new AuthorizationPolicyBuilder ( )
options . AddPolicy ( "Authenticated" , policy = > policy . RequireAuthenticatedUser ( ) ) ;
. AddAuthenticationSchemes ( "Bearer" )
options . AddPolicy ( "IsTheAuthor" , policy = >
. RequireAuthenticatedUser ( ) . Build ( ) ) ;
policy . Requirements . Add ( new EditPermission ( ) ) ) ;
// options.AddPolicy("EmployeeId", policy => policy.RequireClaim("EmployeeId", "123", "456"));
} ) ;
// options.AddPolicy("BuildingEntry", policy => policy.Requirements.Add(new OfficeEntryRequirement()));
options . AddPolicy ( "Authenticated" , policy = > policy . RequireAuthenticatedUser ( ) ) ;
services . AddSingleton < IAuthorizationHandler , PermissionHandler > ( ) ;
options . AddPolicy ( "IsTheAuthor" , policy = >
policy . Requirements . Add ( new EditPermission ( ) ) ) ;
} ) ;
services . AddSingleton < IAuthorizationHandler , PermissionHandler > ( ) ;
return builder . Build ( ) ;
return builder . Build ( ) ;
}
}
public static WebApplication ConfigurePipeline ( this WebApplication app )
public static WebApplication ConfigurePipeline ( this WebApplication app )
{
{
if ( app . Environment . IsDevelopment ( ) )
if ( app . Environment . IsDevelopment ( ) )
{
{
app . UseDeveloperExceptionPage ( ) ;
app . UseDeveloperExceptionPage ( ) ;
}
}
else
else
{
{
app . UseExceptionHandler ( "/Home/Error" ) ;
app . UseExceptionHandler ( "/Home/Error" ) ;
}
}
app . UseStaticFiles ( ) ;
app . UseStaticFiles ( ) ;
app . UseRouting ( ) ;
app . UseRouting ( ) ;
app . UseIdentityServer ( ) ;
app . UseIdentityServer ( ) ;
@ -353,15 +367,15 @@ internal static class HostingExtensions
var googleAuthSettings = services . GetRequiredService < IOptions < GoogleAuthSettings > > ( ) ;
var googleAuthSettings = services . GetRequiredService < IOptions < GoogleAuthSettings > > ( ) ;
var authorizationService = services . GetRequiredService < IAuthorizationService > ( ) ;
var authorizationService = services . GetRequiredService < IAuthorizationService > ( ) ;
var localization = services . GetRequiredService < IStringLocalizer < YavscLocalization > > ( ) ;
var localization = services . GetRequiredService < IStringLocalizer < YavscLocalization > > ( ) ;
Startup . Configure ( app , siteSettings , smtpSettings , authorizationService ,
Startup . Configure ( app , siteSettings , smtpSettings , authorizationService ,
payPalSettings , googleAuthSettings , localization , loggerFactory ,
payPalSettings , googleAuthSettings , localization , loggerFactory ,
app . Environment . EnvironmentName ) ;
app . Environment . EnvironmentName ) ;
app . ConfigureFileServerApp ( ) ;
app . ConfigureFileServerApp ( ) ;
return app ;
return app ;
}
}
static void LoadGoogleConfig ( IConfigurationRoot configuration )
static void LoadGoogleConfig ( IConfigurationRoot configuration )
{
{
string? googleClientFile = configuration [ "Authentication:Google:GoogleWebClientJson" ] ;
string? googleClientFile = configuration [ "Authentication:Google:GoogleWebClientJson" ] ;
string? googleServiceAccountJsonFile = configuration [ "Authentication:Google:GoogleServiceAccountJson" ] ;
string? googleServiceAccountJsonFile = configuration [ "Authentication:Google:GoogleServiceAccountJson" ] ;