fix issues and build and run Successfully ...
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Controllers;
|
||||
using xCommons.Providers;
|
||||
|
||||
@@ -1,177 +0,0 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using xCommons.Attributes;
|
||||
using xCommons.Configurations;
|
||||
using xCommons.Providers;
|
||||
using xIdentityHelper;
|
||||
using xIdentityService.Controllers;
|
||||
using xIdentityService.Interfaces;
|
||||
|
||||
namespace xAiApi.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Test all Authentication Policies ...
|
||||
/// </summary>
|
||||
[RequireXPowered(false)]
|
||||
public class TestIdentityController : XBaseIdentityController
|
||||
{
|
||||
public TestIdentityController(
|
||||
ILogger<TestIdentityController> logger,
|
||||
XAppConfiguration appConfiguration,
|
||||
IXIdentityProvider identityProvider,
|
||||
XValidationProvider validationProvider
|
||||
) : base(
|
||||
logger,
|
||||
appConfiguration,
|
||||
identityProvider,
|
||||
validationProvider
|
||||
)
|
||||
{ }
|
||||
|
||||
//
|
||||
#region Test Actions ...
|
||||
/// <summary>
|
||||
/// API Read Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassReadAccess")]
|
||||
[Authorize (Policy = XPolicies.ReadAccess)]
|
||||
public ActionResult<string> PassReadAccess () {
|
||||
return Ok ("Read Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Write Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassWriteAccess")]
|
||||
[Authorize (Policy = XPolicies.WriteAccess)]
|
||||
public ActionResult<string> PassWriteAccess () {
|
||||
return Ok ("Write Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Admin Scope
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassAdminAccess")]
|
||||
[Authorize (Policy = XPolicies.AdminAccess)]
|
||||
public ActionResult<string> PassAdminAccess () {
|
||||
return Ok ("Admin Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API Manage Scop
|
||||
/// </summary>
|
||||
/// <returns>string message</returns>
|
||||
[HttpGet ("PassManageAccess")]
|
||||
[Authorize (Policy = XPolicies.ManageAccess)]
|
||||
public ActionResult<string> PassManageAccess () {
|
||||
return Ok ("Manage Access Passed ...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Action which returns a List of Authenticated User Claims
|
||||
/// </summary>
|
||||
/// <returns>string message which represent current user's claims</returns>
|
||||
[HttpGet ("HiClaims")]
|
||||
[Authorize (Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiClaims () {
|
||||
//
|
||||
var result = new {
|
||||
name = User?.Identity?.Name,
|
||||
claims = User?.Claims.Select (c => new {
|
||||
c.Type, c.Value
|
||||
})
|
||||
};
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiUser")]
|
||||
[Authorize (Policy = XPolicies.User)]
|
||||
public ActionResult<string> HiUser () {
|
||||
//
|
||||
var result = $"Hi User: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledUser")]
|
||||
[Authorize (Policy = XPolicies.EnabledUser)]
|
||||
public ActionResult<string> HiEnabledUser () {
|
||||
//
|
||||
var result = $"Hi User: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiAgent")]
|
||||
[Authorize (Policy = XPolicies.Agent)]
|
||||
public ActionResult<string> HiAgent () {
|
||||
//
|
||||
var result = $"Hi Agent: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledAgent")]
|
||||
[Authorize (Policy = XPolicies.EnabledAgent)]
|
||||
public ActionResult<string> HiEnabledAgent () {
|
||||
//
|
||||
var result = $"Hi Agent: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiAdmin")]
|
||||
[Authorize (Policy = XPolicies.Admin)]
|
||||
public ActionResult<string> HiAdmin () {
|
||||
//
|
||||
var result = $"Hi Admin: {User?.Identity?.Name} ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// a simple Hello User for Checking Authentication and Policy
|
||||
/// </summary>
|
||||
/// <returns>string message which contains authenticated user name</returns>
|
||||
[HttpGet ("HiEnabledAdmin")]
|
||||
[Authorize (Policy = XPolicies.EnabledAdmin)]
|
||||
public ActionResult<string> HiEnabledAdmin () {
|
||||
//
|
||||
var result = $"Hi Admin: {User?.Identity?.Name} is Enabled ...";
|
||||
|
||||
//
|
||||
return Ok (result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using xCommons.Authorization;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityHelper;
|
||||
@@ -72,9 +75,7 @@ namespace xAiApi.Extensions
|
||||
};
|
||||
|
||||
//
|
||||
#pragma warning disable ASPDEPR005 // Type or member is obsolete
|
||||
forwardOptions.KnownNetworks.Clear();
|
||||
#pragma warning restore ASPDEPR005 // Type or member is obsolete
|
||||
forwardOptions.KnownProxies.Clear();
|
||||
|
||||
//
|
||||
|
||||
+6
-239
@@ -1,22 +1,11 @@
|
||||
// using xHttpService.DI;
|
||||
// using xAiApi.Database;
|
||||
// using xFileService.DI;
|
||||
// using xDataService.DI;
|
||||
// using xPushService.DI;
|
||||
// using System.Text.Json;
|
||||
// using System.Reflection;
|
||||
// using xAiApi.Extensions;
|
||||
// using xStringService.DI;
|
||||
// using xStorageService.DI;
|
||||
// using xCommons.Extensions;
|
||||
// using xDataService.Models;
|
||||
// using xIdentityService.DI;
|
||||
// using xPushService.Helpers;
|
||||
// using xCommons.Configurations;
|
||||
// using System.Text.Json.Serialization;
|
||||
// using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace xAiApi
|
||||
{
|
||||
@@ -35,225 +24,3 @@ namespace xAiApi
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
#region .net 10 Standard ...
|
||||
// //
|
||||
// // Create Application Builder ...
|
||||
// var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// //
|
||||
// #region Register services ...
|
||||
// //
|
||||
// // Register Validation Provider and all XCommons Module Services ...
|
||||
// builder.Services.AddXCommons();
|
||||
|
||||
// //
|
||||
// // Register App Configuration ...
|
||||
// builder.Services.AddXAppConfiguration(builder.Configuration);
|
||||
// var appConfiguration = builder.Services.GetRegisteredService<XAppConfiguration>();
|
||||
|
||||
// //
|
||||
// // Register Allowed Origins ...
|
||||
// builder.Services.AddXCors(appConfiguration.AllowedOrigins);
|
||||
|
||||
// //
|
||||
// // Register Swagger ...
|
||||
// var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||
// var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
||||
// builder.Services.AddXSwagger(builder.Configuration, xmlFilePath: xmlPath);
|
||||
|
||||
// //
|
||||
// // Register HttpService ...
|
||||
// builder.Services.AddXHttpService(builder.Configuration);
|
||||
|
||||
// //
|
||||
// // Add Api V1 Versioning ...
|
||||
// builder.Services.AddXApiV1Versioning();
|
||||
|
||||
// //
|
||||
// // OAuthIntrospectin Http Client Handler ...
|
||||
// // this is for handling SSLErrors ...
|
||||
// builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName)
|
||||
// .ConfigurePrimaryHttpMessageHandler(() =>
|
||||
// {
|
||||
// return new HttpClientHandler
|
||||
// {
|
||||
// ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
|
||||
// };
|
||||
// });
|
||||
|
||||
// //
|
||||
// // Register Authorizations ...
|
||||
// builder.Services.AddXAuthorization();
|
||||
|
||||
// //
|
||||
// // Mapping Controllers ...
|
||||
// builder.Services.AddControllers()
|
||||
// .AddJsonOptions(x =>
|
||||
// {
|
||||
// //
|
||||
// // Optional but recommended for .NET 8+:
|
||||
// // Allows reading properties case-insensitively (e.g., "myProp" matches "MyProp") ...
|
||||
// x.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
|
||||
|
||||
// //
|
||||
// // This tells STJ to ignore circular references instead of throwing an exception ...
|
||||
// x.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
|
||||
|
||||
// //
|
||||
// // Camel Case Naming Policy ...
|
||||
// x.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
|
||||
// });
|
||||
|
||||
// //
|
||||
// var lifeTime = ServiceLifetime.Scoped;
|
||||
// var repositoryType = xDataService.Constants.XRepositoryType.EF;
|
||||
|
||||
// //
|
||||
// // Register XIdentity Service ...
|
||||
// builder.Services.AddXIdentityService(
|
||||
// lifeTime: lifeTime,
|
||||
// configuration: builder.Configuration
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Storage Service ...
|
||||
// builder.Services.AddXStorageService(builder.Configuration);
|
||||
|
||||
// //
|
||||
// // Push Service ...
|
||||
// builder.Services.AddXPushService(
|
||||
// lifeTime: lifeTime,
|
||||
// config: builder.Configuration
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Preparing DataBases ...
|
||||
// var databases = new List<XDatabaseDescriptor>
|
||||
// {
|
||||
// //
|
||||
// // Introduce Ai Api Descriptor ...
|
||||
// new XAiApiDatabaseDescriptor()
|
||||
// };
|
||||
// if (databases.HasChild())
|
||||
// {
|
||||
// //
|
||||
// databases
|
||||
// .ToList()
|
||||
// .ForEach(database =>
|
||||
// {
|
||||
// //
|
||||
// // Register DataBase ...
|
||||
// builder.Services.AddXDatabase(
|
||||
// lifeTime: lifeTime,
|
||||
// descriptor: database,
|
||||
// configuration: builder.Configuration
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Register String Service ...
|
||||
// builder.Services.AddXStringService<XAiApiDbContext>(
|
||||
// lifeTime: lifeTime,
|
||||
// repositoryType: repositoryType
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Register File Service ...
|
||||
// builder.Services.AddXFileService<XAiApiDbContext>(
|
||||
// lifeTime: lifeTime,
|
||||
// repositoryType: repositoryType
|
||||
// );
|
||||
// #endregion
|
||||
|
||||
// //
|
||||
// // Creating Application ...
|
||||
// var app = builder.Build();
|
||||
|
||||
// //
|
||||
// #region Using Middlewares ...
|
||||
// //
|
||||
// // Configure the HTTP request pipeline.
|
||||
// var isDevelopmentEnvironment = false;
|
||||
// if (app.Environment.IsDevelopment())
|
||||
// {
|
||||
// isDevelopmentEnvironment = true;
|
||||
// app.UseDeveloperExceptionPage();
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Use Swagger Middleware ...
|
||||
// app.UseXSwagger();
|
||||
|
||||
// //
|
||||
// // Force Https Redirection ...
|
||||
// app.UseHttpsRedirection();
|
||||
|
||||
// //
|
||||
// // Using Cors ...
|
||||
// app.UseXCors();
|
||||
|
||||
// //
|
||||
// // Using Routing ...
|
||||
// app.UseRouting();
|
||||
|
||||
// //
|
||||
// // Use xIdentityService ...
|
||||
// app.UseXIdentityService();
|
||||
|
||||
// //
|
||||
// // Use Authorization ...
|
||||
// app.UseAuthorization();
|
||||
|
||||
// //
|
||||
// // Using Endpoints ...
|
||||
// app.UseEndpoints(endpoints =>
|
||||
// {
|
||||
// _ = endpoints.MapControllers();
|
||||
// });
|
||||
|
||||
// //
|
||||
// // Use Storage Service ...
|
||||
// app.UseXStorageService();
|
||||
|
||||
// //
|
||||
// // Using DataBase ...
|
||||
// if (databases.HasChild())
|
||||
// {
|
||||
// //
|
||||
// databases
|
||||
// .ToList()
|
||||
// .ForEach(database =>
|
||||
// {
|
||||
// //
|
||||
// app.UseXDatabase(
|
||||
// descriptor: database,
|
||||
// isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Use PushService ...
|
||||
// var pushHelper = new XPushServiceHelper();
|
||||
// app.UseXPushService(pushHelper);
|
||||
|
||||
// //
|
||||
// // Using String Service ...
|
||||
// app.UseXStringService(
|
||||
// isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
// );
|
||||
|
||||
// //
|
||||
// // Using File Service ...
|
||||
// app.UseXFileService(
|
||||
// isDevelopmentEnvironment: isDevelopmentEnvironment
|
||||
// );
|
||||
// #endregion
|
||||
|
||||
// //
|
||||
// // Runing Application ...
|
||||
// app.Run();
|
||||
#endregion
|
||||
@@ -1,20 +1,27 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:6636",
|
||||
"sslPort": 44322
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5012",
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"xAiApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:6001;http://localhost:6000;https://0.0.0.0:6001;",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "weatherforecast",
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
||||
+20
-5
@@ -1,31 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using xTagService.DI;
|
||||
using xHttpService.DI;
|
||||
using System.Net.Http;
|
||||
using xAiApi.Database;
|
||||
using xHttpService.DI;
|
||||
using xPushService.DI;
|
||||
using xFileService.DI;
|
||||
using xDataService.DI;
|
||||
using xPushService.DI;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using xAiApi.Extensions;
|
||||
using xStringService.DI;
|
||||
using xStorageService.DI;
|
||||
using xCommons.Extensions;
|
||||
using xDataService.Models;
|
||||
using xIdentityService.DI;
|
||||
using xPushService.Helpers;
|
||||
using xDataService.Models;
|
||||
using xCommons.Extensions;
|
||||
using xCommons.Configurations;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||
using xPushService.Helpers;
|
||||
|
||||
namespace xAiApi
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
//
|
||||
#region Props ...
|
||||
public IConfiguration Configuration { get; }
|
||||
private readonly List<XDatabaseDescriptor> databases;
|
||||
private readonly XAiApiDatabaseDescriptor apiDatabaseDescriptor;
|
||||
#endregion
|
||||
|
||||
//
|
||||
#region Constructor(s) ...
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
//
|
||||
@@ -39,6 +53,7 @@ namespace xAiApi
|
||||
apiDatabaseDescriptor
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" disableTLSCertificateValidation="true" />
|
||||
<add key="baget" value="https://nuget.saherelmhub.ir/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
+2
-4
@@ -3,14 +3,12 @@
|
||||
<!-- Runtime Definition -->
|
||||
<PropertyGroup>
|
||||
<Version>1.0.0</Version>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<Authors>Hadi Khazaee Asl</Authors>
|
||||
<Company>SaherElm IT Center</Company>
|
||||
<PackageId>xSaherElm.xAiApi</PackageId>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<!-- <TargetFramework>netcoreapp3.1</TargetFramework> -->
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<!-- <TargetFramework>net8.0</TargetFramework> -->
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<Description>
|
||||
a WebAPI Project which contains all Business Logic of xSaherElm Project's AI.
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
@xAiApi_HostAddress = http://localhost:5012
|
||||
|
||||
GET {{xAiApi_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
Reference in New Issue
Block a user