diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/.config/dotnet-tools.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/.config/dotnet-tools.json new file mode 100644 index 0000000..0d1da73 --- /dev/null +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "dotnet-ef": { + "version": "6.0.1", + "commands": [ + "dotnet-ef" + ] + } + } +} \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs index 5d01ce5..cbdb7a6 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs @@ -13,18 +13,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost public class HttpClientInvoker : IHttpClientInvoker { - // private readonly HttpAuthorizationHandler _httpAuthorizationHandler; + private readonly HttpAuthorizationHandler _httpAuthorizationHandler; private readonly string _baseUrl; public HttpClientInvoker(IConfiguration configuration - // , HttpAuthorizationHandler httpAuthorizationHandler + , HttpAuthorizationHandler httpAuthorizationHandler ) { - // _httpAuthorizationHandler = httpAuthorizationHandler; + _httpAuthorizationHandler = httpAuthorizationHandler; _baseUrl = configuration["RemoteServices:Default:BaseUrl"]; } - public async Task InvokeGetAsync(string routeString) + public async Task InvokeGetAsync(string routeString) { var client = CreateClient(); var response = await client.GetAsync(routeString); @@ -33,11 +33,13 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost return dto; } - public async Task InvokePostAsync(TInput input, string routeString) + public async Task InvokePostAsync(TInput input, string routeString) { var client = CreateClient(); var response = await client.PostAsJsonAsync(routeString, input); response.EnsureSuccessStatusCode(); + var str =await response.Content.ReadAsStringAsync(); + var dto = await response.Content.ReadFromJsonAsync(); return dto; } @@ -48,13 +50,13 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost client.BaseAddress = new Uri(_baseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - + //XmlHost也使用Jwt认证,并连到同一个IDS4 server,不需要再手工添加鉴权信息了 - // if (_httpAuthorizationHandler.IsLoggedIn()) - // { - // client.DefaultRequestHeaders.Authorization = - // new AuthenticationHeaderValue("Bearer", _httpAuthorizationHandler.GetCurrentBearer()); - // } + if (_httpAuthorizationHandler.IsLoggedIn()) + { + client.DefaultRequestHeaders.Authorization = + new AuthenticationHeaderValue("Bearer", _httpAuthorizationHandler.GetCurrentBearer()); + } return client; } diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/IHttpClientInvoker.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/IHttpClientInvoker.cs index 361f976..c641a2d 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/IHttpClientInvoker.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/IHttpClientInvoker.cs @@ -5,7 +5,8 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost { public interface IHttpClientInvoker { - Task InvokeGetAsync(string routeString); - Task InvokePostAsync(TInput input, string routeString); + Task InvokeGetAsync(string routeString); + Task InvokePostAsync(TInput input, string routeString); } + } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs index 32a9ddd..71681d1 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Startup.cs @@ -38,14 +38,14 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost private static void DependencyInjection(IServiceCollection services) { services.AddSingleton(typeof(IHttpClientInvoker<,>), typeof(HttpClientInvoker<,>)); - // services.AddSingleton(); - // services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); } private static void ConfigureOptions(IServiceCollection services, IConfiguration configuration) { // services.Configure(configuration.GetSection("BasicAuthentication")); - // services.Configure(configuration.GetSection("RemoteAuthentication")); + services.Configure(configuration.GetSection("RemoteAuthentication")); } private static void ConfigureAuthentication(IServiceCollection services,IConfiguration configuration) diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json index cd33aae..a4bebac 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.Production.json @@ -16,7 +16,14 @@ "AuthServer": { "Authority": "https://scp.iacchina.net:9988", "RequireHttpsMetadata": "false", - "SwaggerClientId": "WebApi_Swagger", + "SwaggerClientId": "WebApi_App", "SwaggerClientSecret": "1q2w3e*" + }, + "RemoteAuthentication": { + "client_id": "WebApi_App", + "client_secret": "1q2w3e*", + "grant_type": "password", + "username": "admin", + "password": "1q2w3E*" } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json index 71410d6..cd2a42a 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/appsettings.json @@ -16,7 +16,14 @@ "AuthServer": { "Authority": "https://localhost:9988", "RequireHttpsMetadata": "false", - "SwaggerClientId": "WebApi_Swagger", + "SwaggerClientId": "WebApi_App", "SwaggerClientSecret": "1q2w3e*" + }, + "RemoteAuthentication": { + "client_id": "WebApi_App", + "client_secret": "1q2w3e*", + "grant_type": "password", + "username": "admin", + "password": "1q2w3E*" } } \ No newline at end of file