Compare commits
13
Commits
247c4eebd9
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c4402ba2b | ||
|
|
889d5b34f6 | ||
|
|
d85314b05a | ||
|
|
18a9b4e7c7 | ||
|
|
f013a46362 | ||
|
|
374c3258ef | ||
|
|
18eb5d92e1 | ||
|
|
c711cae78f | ||
|
|
8bbd05d2c0 | ||
|
|
30a54fac8b | ||
|
|
32ffdd3e5e | ||
|
|
27e9c312f3 | ||
|
|
de9abd2e4a |
@@ -1,6 +1,7 @@
|
||||
#
|
||||
bin
|
||||
obj
|
||||
Logs
|
||||
|
||||
#
|
||||
Db/*
|
||||
|
||||
@@ -1,53 +1,103 @@
|
||||
using System.Linq;
|
||||
using xIdentityHelper;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Authorization;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using xIdentityService.Interfaces;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xIdentityHelper;
|
||||
using xCommons.Authorization;
|
||||
using xCommons.Extensions;
|
||||
|
||||
namespace xApi.Extensions {
|
||||
public static class XStartupExtensions {
|
||||
/// <summary>
|
||||
/// Register Authorization Policies
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="policies"></param>
|
||||
public static void AddXAuthorization (
|
||||
public static void AddXAuthorization(
|
||||
this IServiceCollection services,
|
||||
IDictionary<string, AuthorizationPolicy> policies = null
|
||||
) {
|
||||
)
|
||||
{
|
||||
//
|
||||
services.AddAuthorization (options => {
|
||||
var policyHandler = services.GetRegisteredService<IXPolicyHandler>();
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
//
|
||||
if (!policies.IsNull ()) {
|
||||
if (!policies.IsNull())
|
||||
{
|
||||
//
|
||||
// Fill Policies ...
|
||||
using (var policiesEnumerator = policies.GetEnumerator ()) {
|
||||
while (policiesEnumerator.MoveNext ()) {
|
||||
using (var policiesEnumerator = policies.GetEnumerator())
|
||||
{
|
||||
while (policiesEnumerator.MoveNext())
|
||||
{
|
||||
var policyDescriptor = policiesEnumerator.Current;
|
||||
options.AddPolicy (policyDescriptor.Key, policyDescriptor.Value);
|
||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||
|
||||
//
|
||||
// Add Policy to Policy Handler ...
|
||||
if (!policyHandler.IsNull())
|
||||
{
|
||||
//
|
||||
// Check Policy is RequiredRole Policy ...
|
||||
var roleRequirements = policyDescriptor.Value.Requirements
|
||||
.OfType<RequiredRolesRequirement>()
|
||||
.FirstOrDefault();
|
||||
if (!roleRequirements.IsNull() &&
|
||||
roleRequirements.Roles.HasChild())
|
||||
{
|
||||
//
|
||||
policyHandler.AddPolicy(
|
||||
policy: policyDescriptor.Key.ToNormalString(),
|
||||
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
var xPolicies = XAuthorizationHelper.GetXAuthorizationPolicies ();
|
||||
if (!xPolicies.IsNull ()) {
|
||||
var xPolicies = XAuthorizationHelper.GetXAuthorizationPolicies();
|
||||
if (!xPolicies.IsNull())
|
||||
{
|
||||
//
|
||||
// Fill Policies ...
|
||||
using (var policiesEnumerator = xPolicies.GetEnumerator ()) {
|
||||
while (policiesEnumerator.MoveNext ()) {
|
||||
using (var policiesEnumerator = xPolicies.GetEnumerator())
|
||||
{
|
||||
while (policiesEnumerator.MoveNext())
|
||||
{
|
||||
//
|
||||
var policyDescriptor = policiesEnumerator.Current;
|
||||
options.AddPolicy (policyDescriptor.Key, policyDescriptor.Value);
|
||||
|
||||
//
|
||||
// Add Policy to Authorization ...
|
||||
options.AddPolicy(policyDescriptor.Key, policyDescriptor.Value);
|
||||
|
||||
//
|
||||
// Add Policy to Policy Handler ...
|
||||
if (!policyHandler.IsNull())
|
||||
{
|
||||
//
|
||||
// Check Policy is RequiredRole Policy ...
|
||||
var roleRequirements = policyDescriptor.Value.Requirements
|
||||
.OfType<RequiredRolesRequirement>()
|
||||
.FirstOrDefault();
|
||||
if (!roleRequirements.IsNull() &&
|
||||
roleRequirements.Roles.HasChild())
|
||||
{
|
||||
//
|
||||
policyHandler.AddPolicy(
|
||||
policy: policyDescriptor.Key.ToNormalString(),
|
||||
requiredRoles: roleRequirements.Roles.Select(r => r.ToNormalString())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
services.AddSingleton<IAuthorizationHandler, RequiredRolesHandler> ();
|
||||
services.AddSingleton<IAuthorizationHandler, RequiredRolesHandler>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+16
-6
@@ -1,3 +1,4 @@
|
||||
using xLoggingService.DI;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
@@ -10,11 +11,20 @@ namespace xApi
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
{
|
||||
//
|
||||
var result = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureLogging(logging =>
|
||||
logging.AddXTelemetryLogger())
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
})
|
||||
.AddXTelemetry();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
-5
@@ -6,6 +6,7 @@ using Newtonsoft.Json;
|
||||
using xApi.Extensions;
|
||||
using xHttpService.DI;
|
||||
using System.Reflection;
|
||||
using xLoggingService.DI;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Models;
|
||||
using xIdentityService.DI;
|
||||
@@ -13,7 +14,6 @@ using xServices.Databases;
|
||||
using xCommons.Configurations;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using xIdentityService.Middlewares;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
@@ -44,13 +44,17 @@ namespace xApi
|
||||
{
|
||||
//
|
||||
// Register Validation Provider and all XCommons Module Services ...
|
||||
services.AddXCommons();
|
||||
services.AddXCommons(Configuration);
|
||||
|
||||
//
|
||||
// Register App Configuration ...
|
||||
services.AddXAppConfiguration(Configuration);
|
||||
var appConfiguration = services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
//
|
||||
// Register Logging Service ...
|
||||
services.AddXLoggingService(Configuration);
|
||||
|
||||
//
|
||||
// Register Allowed Origins ...
|
||||
services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
@@ -120,14 +124,22 @@ namespace xApi
|
||||
);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
public void Configure(
|
||||
IApplicationBuilder app,
|
||||
IWebHostEnvironment env
|
||||
)
|
||||
{
|
||||
//
|
||||
if (env.IsDevelopment())
|
||||
var isDevelopmentEnvironment = env.IsDevelopment();
|
||||
if (isDevelopmentEnvironment)
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
//
|
||||
// Setting Environment in App Confiuration ...
|
||||
app.AddEnvironmentToXAppConfiguration(env.EnvironmentName);
|
||||
|
||||
//
|
||||
// Use Swagger Middleware ...
|
||||
app.UseXSwagger();
|
||||
@@ -143,6 +155,14 @@ namespace xApi
|
||||
app.UseRouting();
|
||||
|
||||
//
|
||||
// Using Request Logging ...
|
||||
if (!isDevelopmentEnvironment)
|
||||
{
|
||||
app.UseXRequestLogger();
|
||||
}
|
||||
|
||||
//
|
||||
// Enable Api Key Usage Logs ...
|
||||
// app.UseXApiKeyUsage();
|
||||
|
||||
//
|
||||
@@ -169,4 +189,6 @@ namespace xApi
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+41
-5
@@ -4,10 +4,8 @@
|
||||
"DefaultLanguage": "fa-IR",
|
||||
"XPoweredValue": "SaherElmITCenter",
|
||||
"WelcomeMessage": "Welcome to xSaherElm Project's API",
|
||||
"AllowedOrigins": [
|
||||
"http://saherelm.ir",
|
||||
"https://saherelm.ir"
|
||||
],
|
||||
"AllowedOrigins": ["http://saherelm.ir", "https://saherelm.ir"],
|
||||
"DefaultCacheTtlMinutes": 10,
|
||||
"SwaggerConfiguration": {
|
||||
"Version": "v1.0",
|
||||
"Title": "xSaherElm API",
|
||||
@@ -180,6 +178,44 @@
|
||||
"XPoweredValue": "SaherElmITCenter",
|
||||
"DefaultClientTimeout": -1
|
||||
},
|
||||
"BotServiceConfiguration": {
|
||||
"VerificationCodeTTL": 5,
|
||||
"DefaultClientTimeout": 3600,
|
||||
"BaseRoute": "https://tapi.bale.ai",
|
||||
"Token": "57317004:D2I9H0KWq2rTB44hHlZ7fOCa9oTgUU6RGIg"
|
||||
},
|
||||
"LoggingServiceConfiguration": {
|
||||
"Enabled": true,
|
||||
"MinimumLevel": "Information",
|
||||
"Queue": {
|
||||
"Enabled": true,
|
||||
"Capacity": 10000,
|
||||
"ShutdownTimeoutSeconds": 10
|
||||
},
|
||||
"File": {
|
||||
"Enabled": true,
|
||||
"Format": "Json",
|
||||
"Directory": "./Logs",
|
||||
"FileName": "xApi-.log",
|
||||
"MinimumLevel": "Information",
|
||||
"RetainedFileCountLimit": 30
|
||||
},
|
||||
"Database": {
|
||||
"Enabled": false,
|
||||
"TableName": "XLogs",
|
||||
"AutoCreateTable": true,
|
||||
"MinimumLevel": "Warning",
|
||||
"Provider": "Microsoft.Data.Sqlite",
|
||||
"ConnectionString": "Filename=./Db/XLogs.db"
|
||||
},
|
||||
"Event": {
|
||||
"Enabled": false,
|
||||
"Sender": "xApi",
|
||||
"MinimumLevel": "Error",
|
||||
"Topic": "application-logs",
|
||||
"Action": "ApplicationLogCreated"
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
@@ -188,4 +224,4 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
}
|
||||
|
||||
+16
-13
@@ -1,4 +1,5 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<!-- Runtime Definition -->
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0</Version>
|
||||
@@ -7,47 +8,48 @@
|
||||
<PackageId>xSaherElm.xApi</PackageId>
|
||||
<Company>SaherElm IT Center</Company>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
|
||||
<Description>
|
||||
a WebAPI Project which contains all Business Logic of xSaherElm Project.
|
||||
</Description>
|
||||
|
||||
|
||||
<!-- Icon Definition -->
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
|
||||
|
||||
<!-- Fix Duplicate TargetFramework Issue -->
|
||||
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<!-- Icon Handling -->
|
||||
<ItemGroup>
|
||||
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true"
|
||||
PackagePath="\icon.png" />
|
||||
<None Include="../../Resources/Images/favicon.png" Link="icon.png" Pack="true" PackagePath="\icon.png" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!-- Local Dependencies -->
|
||||
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Local Projects -->
|
||||
<ItemGroup>
|
||||
<!-- All Modules Has Dependencies in xService -->
|
||||
<ProjectReference Include="..\Modules\xServices\xServices.csproj" />
|
||||
<ProjectReference Include="..\Modules\xLoggingService\xLoggingService.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!-- Dependencies -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.11" />
|
||||
<PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!-- For XML Documentation Support -->
|
||||
<PropertyGroup>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<!-- Ef Core -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
|
||||
@@ -55,9 +57,10 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<!-- Create Required Folders -->
|
||||
<Target Name="CreateRequiredFolder" AfterTargets="AfterPublish">
|
||||
<MakeDir Directories="$(PublishDir)wwwroot" Condition="!Exists('$(PublishDir)wwwroot')" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user