public MobileSecondHandChatHub(IChatHubCacheService chatHubCacheService, TokenAuthorizationOptions tokenAuthorizationOptions, IConversationService conversationService)
		{
			this.chatHubCacheService = chatHubCacheService;
			this.tokenAuthorizationOptions = tokenAuthorizationOptions;
			this.handler = new JwtSecurityTokenHandler();
			this.conversationService = conversationService;
		}
		private static void RegisterTokenAuthorizationOptions(IServiceCollection services) {
			//in production keep RSACryptoServiceProvider in save place
			RSACryptoServiceProvider keyService = new RSACryptoServiceProvider(2048);
			var xmlString = String.Empty;
			var path = @"C:\Users\marcianno\Documents\Key\RsaProvider.txt";
			using (StreamReader sw = new StreamReader(path)) {
				xmlString = sw.ReadToEnd();
			}

			keyService.FromXmlString(xmlString);
			RsaSecurityKey key = new RsaSecurityKey(keyService.ExportParameters(true));

			var tokenOptions = new TokenAuthorizationOptions {
				Audience = "MobileSecondHandApp",
				Issuer = "MarcinSzyszka",
				SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSha256Signature)
			};
			services.AddSingleton<TokenAuthorizationOptions>(tokenOptions);
		}
		public ApplicationSignInManager(SignInManager<ApplicationUser> signInManager, IApplicationUserManager applicationUserManager, IFacebookApiManager facebookApiManager, TokenAuthorizationOptions tokenAuthorizationOptions) {
			this.signInManager = signInManager;
			this.applicationUserManager = applicationUserManager;
			this.facebookApiManager = facebookApiManager;
			this.tokenAuthorizationOptions = tokenAuthorizationOptions;
		}
		// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
		public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, TokenAuthorizationOptions tokenAuthorizationOptions) {
			loggerFactory.AddConsole(Configuration.GetSection("Logging"));
			loggerFactory.AddDebug();

			app.UseApplicationInsightsRequestTelemetry();

			if (env.IsDevelopment()) {
				app.UseDeveloperExceptionPage();
				app.UseDatabaseErrorPage();
				app.UseBrowserLink();
			}
			else {
				app.UseExceptionHandler("/Home/Error");

				// For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859
				try {
					using (var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>()
						.CreateScope()) {
						serviceScope.ServiceProvider.GetService<MobileSecondHandContext>()
							 .Database.Migrate();
					}
				} catch { }
			}

			app.UseApplicationInsightsExceptionTelemetry();

			app.UseStaticFiles();

			app.Use(next => async ctx => {
				try {
					await next(ctx);
				} catch (Exception exc) {
					if (ctx.Response.HasStarted) {
						throw exc;
					}

					ctx.Response.StatusCode = 401;
				}
			});

			app.UseJwtBearerAuthentication(GetJwtBearerOptions(tokenAuthorizationOptions));

			app.UseIdentity();

			app.UseFacebookAuthentication(GetFacebookOptions(Configuration));
			// Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715

			app.UseMvc(routes => {
				routes.MapRoute(
					name: "default",
					template: "{controller=Home}/{action=Index}/{id?}");
			});

			app.UseCors("myPolicy");

			app.UseSignalR();
			//app.UseWebSockets();
		}
		private JwtBearerOptions GetJwtBearerOptions(TokenAuthorizationOptions tokenAuthorizationOptions) {
			var options = new JwtBearerOptions();
			options.TokenValidationParameters.IssuerSigningKey = tokenAuthorizationOptions.SigningCredentials.Key;
			options.TokenValidationParameters.ValidAudience = tokenAuthorizationOptions.Audience;
			options.TokenValidationParameters.ValidIssuer = tokenAuthorizationOptions.Issuer;
			options.TokenValidationParameters.ValidateLifetime = true;
			options.TokenValidationParameters.ClockSkew = TimeSpan.Zero;

			return options;
		}