Hey guys,So I'm trying to deploy an IdentityServer4 Authentication Server.I have deployed apps (that doesn't use X509Certificate).I've published my app it the IIS seems to be working but I can't communicate with it because of the SSL Certificate.My startup page class:
public class Startup { private IConfiguration Configuration { get; set; } public Startup(IHostingEnvironment environment) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.SetBasePath(environment.ContentRootPath); builder.AddJsonFile("appsettings.json"); builder.AddEnvironmentVariables(); Configuration = builder.Build(); } public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddSigningCredential(new X509Certificate2( Configuration.GetSection("Addresses").GetValue<string>("RSA"), "password")) .AddInMemoryApiResources(InMemoryConfiguration.ApiResources()) .AddInMemoryClients(InMemoryConfiguration.Clients()) .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>(); services.AddTransient<IUserData, SqlUserRepository>(); services.AddDbContext<DbContextUser>(options => options.UseSqlServer(Configuration.GetConnectionString("MainServer"))); } public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseDeveloperExceptionPage(); app.UseIdentityServer(); app.UseStaticFiles(); } }
Everything was working great on my computer.That's the logs I get from the appPool of my IdentityServer 4 app :
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:\Users\swap.authserver.com\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. info: IdentityServer4.Startup[0] Starting IdentityServer4 version 2.4.0.0 info: IdentityServer4.Startup[0] You are using the in-memory version of the persisted grant store. This will store consent decisions, authorization codes, refresh and reference tokens in memory only. If you are using any of those features in production, you want to switch to a different store implementation. info: IdentityServer4.Startup[0] Using the default authentication scheme idsrv for IdentityServer Hosting environment: Production Content root path: C:\SwapPublish\AuthServer Now listening on: http://127.0.0.1:27839 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:5001/ info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 102.4928ms 404
Everything seems fine.
When I send a request to get token (AKA URL https://localhost:5001/connect/token) I get this log from my API app :
warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50] Using an in-memory repository. Keys will not be persisted to storage. warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59] Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits. info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58] Creating key {2f6cbe8f-3454-4d1a-a4b7-d07cd2a593cb} with creation date 2019-05-19 17:59:53Z, activation date 2019-05-19 17:59:53Z, and expiration date 2019-08-17 17:59:53Z. warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {2f6cbe8f-3454-4d1a-a4b7-d07cd2a593cb} may be persisted to storage in unencrypted form. Hosting environment: Production Content root path: C:\SwapPublish\API Now listening on: http://127.0.0.1:33388 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 POST http://vmedu184.mtacloud.co.il/user/signup text/plain;charset=UTF-8 83 info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1] Route matched with {action = "Signup", controller = "User"}. Executing action SwapExperimental.Controllers.UserController.Signup (Swap.Api) info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1] Executing action method SwapExperimental.Controllers.UserController.Signup (Swap.Api) - Validation state: Valid info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 2.1.8-servicing-32085 initialized 'DbContextUser' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (5ms) [Parameters=[@__email_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30'] SELECT TOP(1) [user].[Id], [user].[CellPhone], [user].[City], [user].[Email], [user].[FirstName], [user].[LastName], [user].[Password], [user].[SignUpDate], [user].[Token] FROM [Users] AS [user] WHERE [user].[Email] = @__email_0 info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (1ms) [Parameters=[@p0='?' (Size = 4000), @p1='?' (Size = 4000), @p2='?' (Size = 450), @p3='?' (Size = 4000), @p4='?' (Size = 4000), @p5='?' (Size = 4000), @p6='?' (DbType = DateTime2), @p7='?' (Size = 4000)], CommandType='Text', CommandTimeout='30'] SET NOCOUNT ON; INSERT INTO [Users] ([CellPhone], [City], [Email], [FirstName], [LastName], [Password], [SignUpDate], [Token]) VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7); SELECT [Id] FROM [Users] WHERE @@ROWCOUNT = 1 AND [Id] = scope_identity(); info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2] Executed action SwapExperimental.Controllers.UserController.Signup (Swap.Api) in 776.3644ms fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HLMSGF60JMF7", Request id "0HLMSGF60JMF7:00000001": An unhandled exception was thrown by the application. System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host --- End of inner exception stack trace --- at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request) at System.Net.Security.SslState.ThrowIfExceptional() at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Swap.Api.Tools.AuthServerHttpClient.GetAccessTokenPack(User user) in D:\Programming Projects\Swap\SwapExperimental\SwapExperimental\Tools\AuthServerHttpClient.cs:line 39 --- End of inner exception stack trace --- at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at Swap.Api.Tools.AuthServerHttpClient.GetAccessToken(User user) in D:\Programming Projects\Swap\SwapExperimental\SwapExperimental\Tools\AuthServerHttpClient.cs:line 34 at SwapExperimental.Controllers.UserController.Signup() in D:\Programming Projects\Swap\SwapExperimental\SwapExperimental\Controllers\UserController.cs:line 43 at lambda_method(Closure , Object , Object[] ) at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters) at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsTContext ---> (Inner Exception #0) System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host --- End of inner exception stack trace --- at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request) at System.Net.Security.SslState.ThrowIfExceptional() at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar) at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask1 creationTask) at System.Threading.Tasks.ValueTask1.get_Result() at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Swap.Api.Tools.AuthServerHttpClient.GetAccessTokenPack(User user) in D:\Programming Projects\Swap\SwapExperimental\SwapExperimental\Tools\AuthServerHttpClient.cs:line 39<--- info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 993.7944ms 500
btw, when I try to open my authserver in browser, I get this message saying :
https://i.redd.it/mma50lplj7z21.png
and if I try to open Exe file :
https://i.redd.it/0bj6lnjtj7z21.png
No idea why does it happen, Can anyone shed light?
Thank you.
Deploying IdentityServer 4 on IIS