Browse Source

[add] 访问RemoteService时支持Bearer Authentication

master
贾荣国 3 years ago
parent
commit
74fa8e263f
  1. 1
      WebApiService/.gitignore
  2. 39
      WebApiService/src/TestHost/Controllers/WeatherForecastController.cs
  3. 26
      WebApiService/src/TestHost/Program.cs
  4. 31
      WebApiService/src/TestHost/Properties/launchSettings.json
  5. 29
      WebApiService/src/TestHost/Startup.cs
  6. 17
      WebApiService/src/TestHost/TestHost.csproj
  7. 47
      WebApiService/src/TestHost/TestModule.cs
  8. 15
      WebApiService/src/TestHost/WeatherForecast.cs
  9. 10
      WebApiService/src/TestHost/appsettings.json
  10. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json
  11. 11
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs
  12. 9
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs
  13. 7
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs
  14. 23
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs
  15. 2
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs
  16. 9
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs
  17. 171
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt
  18. 4
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs
  19. 59
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs
  20. 1
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj
  21. 0
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.Development.json
  22. 20
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json
  23. 13
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json

1
WebApiService/.gitignore

@ -21,6 +21,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015 cache/options directory
.vs/

39
WebApiService/src/TestHost/Controllers/WeatherForecastController.cs

@ -1,39 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestHost.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
}
}

26
WebApiService/src/TestHost/Program.cs

@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestHost
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).UseAutofac();
}
}

31
WebApiService/src/TestHost/Properties/launchSettings.json

@ -1,31 +0,0 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33955",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TestHost": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

29
WebApiService/src/TestHost/Startup.cs

@ -1,29 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace TestHost
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddApplication<TestModule>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
app.InitializeApplication();
}
}
}

17
WebApiService/src/TestHost/TestHost.csproj

@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.3" />
<PackageReference Include="Volo.Abp.Core" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Autofac" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Http.Client" Version="4.4.2" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="4.4.2" />
</ItemGroup>
</Project>

47
WebApiService/src/TestHost/TestModule.cs

@ -1,47 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Volo.Abp;
using Volo.Abp.Modularity;
namespace TestHost
{
public class TestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var services = context.Services;
services.AddControllers();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "TestHost", Version = "v1" });
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
var env = context.GetEnvironment();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TestHost v1"));
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}

15
WebApiService/src/TestHost/WeatherForecast.cs

@ -1,15 +0,0 @@
using System;
namespace TestHost
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}

10
WebApiService/src/TestHost/appsettings.json

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json

@ -38,5 +38,5 @@
}
}
},
"AlwaysAllowAuthorization": true
"AlwaysAllowAuthorization": false
}

11
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/BaererToken.cs

@ -0,0 +1,11 @@
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
public class BaererToken
{
public string access_token { get; set; }
public long expires_in { get; set; }
public string token_type { get; set; }
public string refresh_token { get; set; }
public string scope { get; set; }
}
}

9
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs

@ -1,13 +1,7 @@
using System;
using System.Diagnostics.Eventing.Reader;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Net.Mime;
using System.Net.Mime;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RestSharp;
namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
{
@ -33,6 +27,7 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers
public virtual async Task<ActionResult<PartDTO>> CreateAsync([FromBody]PartCreateDto input)
{
var dto = await _httpClientInvoker.InvokeAsync(input, RouteConsts.Part);
return Ok(dto);

7
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/GlobalCache.cs

@ -0,0 +1,7 @@
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
public static class GlobalCache
{
public static BaererToken BearerToken { get; set; }
}
}

23
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvoker.cs

@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
@ -6,6 +7,7 @@ using System.Runtime.Serialization;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
@ -13,20 +15,39 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost
public class HttpClientInvoker<TInput, TOutput> : IHttpClientInvoker<TInput, TOutput>
{
private readonly IConfiguration _configuration;
private readonly ITokenService _tokenService;
public HttpClientInvoker(IConfiguration configuration)
public HttpClientInvoker(IConfiguration configuration,ITokenService tokenService)
{
_configuration = configuration;
_tokenService = tokenService;
}
public async Task<TOutput> InvokeAsync(TInput input,string routeString)
{
var baseUrl = _configuration["RemoteServices:Default:BaseUrl"];
if (GlobalCache.BearerToken==null)
{
var token =await _tokenService.GetToken(baseUrl);
GlobalCache.BearerToken = token;
}
var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", GlobalCache.BearerToken.access_token);
var response = await client.PostAsJsonAsync(routeString, input);
if (response.StatusCode == HttpStatusCode.Unauthorized)
{
var token = await _tokenService.GetToken(baseUrl);
GlobalCache.BearerToken = token;
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", GlobalCache.BearerToken.access_token);
response = await client.PostAsJsonAsync(routeString, input);
}
response.EnsureSuccessStatusCode();
var dto = await response.Content.ReadFromJsonAsync<TOutput>();

2
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/IHttpClientInvoker.cs

@ -3,7 +3,7 @@ using System.Threading.Tasks;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
public interface IHttpClientInvoker<TInput,TOutput>
public interface IHttpClientInvoker<in TInput,TOutput>
{
Task<TOutput> InvokeAsync(TInput input,string routeString);
}

9
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/ITokenService.cs

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
public interface ITokenService
{
Task<BaererToken> GetToken(string baseUrl);
}
}

171
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Logs/logs.txt

@ -5422,3 +5422,174 @@ System.Runtime.Serialization.InvalidDataContractException: Type 'Win_in.Sfs.Scp.
2022-01-12 17:38:33.402 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 3855.5986ms
2022-01-12 17:38:33.403 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PurchaseOrderController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-12 17:38:33.404 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/po application/xml 964 - 200 1410 application/xml;+charset=utf-8 3922.8488ms
2022-01-13 08:53:44.176 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-13 08:53:45.198 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-13 08:53:46.004 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-13 08:53:46.005 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-13 08:53:46.005 +08:00 [INF] Hosting environment: Development
2022-01-13 08:53:46.005 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-13 08:53:48.372 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-13 08:53:48.995 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 625.6764ms
2022-01-13 08:53:49.022 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-13 08:53:49.024 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.2176ms
2022-01-13 08:53:49.933 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-13 08:53:50.331 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 397.9020ms
2022-01-13 08:53:58.518 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530
2022-01-13 08:53:58.550 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 08:53:58.554 +08:00 [INF] Authorization was successful.
2022-01-13 08:53:58.555 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 08:53:58.578 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 08:54:05.184 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 08:55:18.395 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 79813.4276ms
2022-01-13 08:55:18.396 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 08:55:18.398 +08:00 [ERR] An unhandled exception has occurred while executing the request.
System.Net.Http.HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Win_in.Sfs.Scp.WebApi.XmlHost.HttpClientInvoker`2.InvokeAsync(TInput input, String routeString) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\HttpClientInvoker.cs:line 48
at Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync(PartCreateDto input) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\Controllers\PartController.cs:line 33
at lambda_method5(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2022-01-13 08:55:18.466 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 500 - text/plain 79948.9728ms
2022-01-13 08:56:16.120 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-13 08:56:17.134 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-13 08:56:18.106 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-13 08:56:18.106 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-13 08:56:18.106 +08:00 [INF] Hosting environment: Development
2022-01-13 08:56:18.106 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-13 08:56:19.982 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-13 08:56:20.458 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 479.1275ms
2022-01-13 08:56:20.488 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-13 08:56:20.499 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 10.8635ms
2022-01-13 08:56:21.434 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-13 08:56:21.828 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 393.4071ms
2022-01-13 08:56:26.014 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530
2022-01-13 08:56:26.045 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 08:56:26.050 +08:00 [INF] Authorization was successful.
2022-01-13 08:56:26.051 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 08:56:26.074 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 08:56:26.156 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 08:58:36.683 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 130523.7861ms.
2022-01-13 08:58:36.689 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'.
2022-01-13 08:58:36.700 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 130623.2582ms
2022-01-13 08:58:36.701 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 08:58:36.702 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 200 1021 application/xml;+charset=utf-8 130687.6750ms
2022-01-13 09:11:40.198 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-13 09:11:41.235 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-13 09:11:41.857 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-13 09:11:41.857 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-13 09:11:41.857 +08:00 [INF] Hosting environment: Development
2022-01-13 09:11:41.857 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-13 09:11:43.551 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-13 09:11:44.091 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 543.2222ms
2022-01-13 09:11:44.172 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-13 09:11:44.176 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 4.0994ms
2022-01-13 09:11:45.373 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-13 09:11:45.739 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 365.7910ms
2022-01-13 09:11:50.087 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530
2022-01-13 09:11:50.120 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 09:11:50.125 +08:00 [INF] Authorization was successful.
2022-01-13 09:11:50.125 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:11:50.154 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 09:11:50.237 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 09:11:57.235 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 7077.9874ms
2022-01-13 09:11:57.236 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:11:57.239 +08:00 [ERR] An unhandled exception has occurred while executing the request.
System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Win_in.Sfs.Scp.WebApi.XmlHost.TokenService.GetToken(String baseUrl) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\TokenService.cs:line 41
at Win_in.Sfs.Scp.WebApi.XmlHost.HttpClientInvoker`2.InvokeAsync(TInput input, String routeString) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\HttpClientInvoker.cs:line 32
at Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync(PartCreateDto input) in D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host\Controllers\PartController.cs:line 33
at lambda_method5(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
2022-01-13 09:11:57.299 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 500 - text/plain 7212.5987ms
2022-01-13 09:12:56.964 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-13 09:12:58.076 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-13 09:12:58.720 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-13 09:12:58.720 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-13 09:12:58.720 +08:00 [INF] Hosting environment: Development
2022-01-13 09:12:58.720 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-13 09:13:00.951 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-13 09:13:01.950 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 1002.3584ms
2022-01-13 09:13:02.003 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-13 09:13:02.006 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 2.3672ms
2022-01-13 09:13:03.450 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-13 09:13:03.815 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 364.0941ms
2022-01-13 09:13:07.659 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530
2022-01-13 09:13:07.691 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 09:13:07.696 +08:00 [INF] Authorization was successful.
2022-01-13 09:13:07.697 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:13:07.720 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 09:13:07.805 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 09:13:20.421 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 12613.534ms.
2022-01-13 09:13:20.426 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'.
2022-01-13 09:13:20.438 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 12714.7336ms
2022-01-13 09:13:20.438 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:13:20.439 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 530 - 200 1021 application/xml;+charset=utf-8 12780.2266ms
2022-01-13 09:13:44.917 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 521
2022-01-13 09:13:44.926 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 09:13:44.926 +08:00 [INF] Authorization was successful.
2022-01-13 09:13:44.926 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:13:44.927 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 09:13:44.943 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 09:14:07.260 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 22316.3022ms.
2022-01-13 09:14:07.260 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'.
2022-01-13 09:14:07.261 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 22334.6268ms
2022-01-13 09:14:07.262 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:14:07.262 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 521 - 200 1012 application/xml;+charset=utf-8 22344.2843ms
2022-01-13 09:16:27.324 +08:00 [INF] Starting Win_in.Sfs.Scp.WebApi.Xml.Host.
2022-01-13 09:16:28.196 +08:00 [INF] User profile is available. Using 'C:\Users\changketec\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
2022-01-13 09:16:28.718 +08:00 [INF] Now listening on: https://localhost:9977
2022-01-13 09:16:28.718 +08:00 [INF] Application started. Press Ctrl+C to shut down.
2022-01-13 09:16:28.718 +08:00 [INF] Hosting environment: Development
2022-01-13 09:16:28.718 +08:00 [INF] Content root path: D:\Work\SFS\Backend\Scp\WebApiService\src\Win_in.Sfs.Scp.WebApi.Xml.Host
2022-01-13 09:16:30.678 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/index.html - -
2022-01-13 09:16:31.284 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/index.html - - - 200 - text/html;charset=utf-8 608.6128ms
2022-01-13 09:16:31.544 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - -
2022-01-13 09:16:31.549 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/_framework/aspnetcore-browser-refresh.js - - - 200 11964 application/javascript;+charset=utf-8 5.0737ms
2022-01-13 09:16:32.254 +08:00 [INF] Request starting HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - -
2022-01-13 09:16:32.607 +08:00 [INF] Request finished HTTP/2 GET https://localhost:9977/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 353.1926ms
2022-01-13 09:18:00.106 +08:00 [INF] Request starting HTTP/2 POST https://localhost:9977/api/scp/part application/xml 543
2022-01-13 09:18:00.139 +08:00 [DBG] AuthenticationScheme: BasicAuthentication was successfully authenticated.
2022-01-13 09:18:00.145 +08:00 [INF] Authorization was successful.
2022-01-13 09:18:00.145 +08:00 [INF] Executing endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:18:00.168 +08:00 [INF] Route matched with {action = "Create", controller = "Part"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.ActionResult`1[Win_in.Sfs.Scp.WebApi.PartDTO]] CreateAsync(Win_in.Sfs.Scp.WebApi.PartCreateDto) on controller Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController (Win_in.Sfs.Scp.WebApi.Xml.Host).
2022-01-13 09:18:00.257 +08:00 [INF] Executing action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) - Validation state: "Valid"
2022-01-13 09:18:16.251 +08:00 [INF] Executed action method Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 15989.5235ms.
2022-01-13 09:18:16.257 +08:00 [INF] Executing OkObjectResult, writing value of type 'Win_in.Sfs.Scp.WebApi.PartDTO'.
2022-01-13 09:18:16.269 +08:00 [INF] Executed action Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host) in 16097.5245ms
2022-01-13 09:18:16.269 +08:00 [INF] Executed endpoint 'Win_in.Sfs.Scp.WebApi.XmlHost.Controllers.PartController.CreateAsync (Win_in.Sfs.Scp.WebApi.Xml.Host)'
2022-01-13 09:18:16.271 +08:00 [INF] Request finished HTTP/2 POST https://localhost:9977/api/scp/part application/xml 543 - 200 1034 application/xml;+charset=utf-8 16164.5237ms

4
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs

@ -48,9 +48,11 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost
services.Configure<BasicAuthenticationOptions>(configuration.GetSection("BasicAuthentication"));
services.Configure<RemoteAuthenticationOptions>(configuration.GetSection("RemoteAuthentication"));
services.AddSingleton(typeof(IHttpClientInvoker<,>),typeof(HttpClientInvoker<,>));
services.AddSingleton<ITokenService, TokenService>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)

59
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/TokenService.cs

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
namespace Win_in.Sfs.Scp.WebApi.XmlHost
{
public class TokenService:ITokenService
{
private readonly IConfiguration _configuration;
private readonly RemoteAuthenticationOptions _options;
public TokenService(IConfiguration configuration,IOptions<RemoteAuthenticationOptions> options)
{
_configuration = configuration;
_options = options.Value;
}
public async Task<BaererToken> GetToken(string baseUrl)
{
const string routeString = "connect/token";
var client = new HttpClient();
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("client_id",_options.client_id),
new KeyValuePair<string, string>("client_secret",_options.client_secret),
new KeyValuePair<string, string>("grant_type",_options.grant_type),
new KeyValuePair<string, string>("username",_options.username),
new KeyValuePair<string, string>("password",_options.password),
});
var response = await client.PostAsync(routeString, content);
response.EnsureSuccessStatusCode();
var dto = await response.Content.ReadFromJsonAsync<BaererToken>();
return dto;
}
}
public class RemoteAuthenticationOptions
{
public string client_id { get; set; }
public string client_secret { get; set; }
public string grant_type { get; set; }
public string username { get; set; }
public string password { get; set; }
}
}

1
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Win_in.Sfs.Scp.WebApi.Xml.Host.csproj

@ -8,7 +8,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="2.2.0" />
<PackageReference Include="RestSharp" Version="107.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.3" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" />

0
WebApiService/src/TestHost/appsettings.Development.json → WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.Development.json

20
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json

@ -0,0 +1,20 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"RemoteServices": {
"Default": {
"BaseUrl": "https://scp.iacchina.net:9988/"
}
},
"BasicAuthentication": {
"Username": "admin",
"Password": "admin"
}
}

13
WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json

@ -15,6 +15,13 @@
},
"BasicAuthentication": {
"Username": "admin",
"Password": "admin"
}
}
"Password": "admin"
},
"RemoteAuthentication": {
"client_id": "WebApi_App",
"client_secret": "1q2w3e*",
"grant_type": "password",
"username": "admin",
"password": "1q2w3E*"
}
}
Loading…
Cancel
Save