public async Task SessionExpiredTest() { var storage = new MemoryStorage(); storage.SaveData(new ApiUserData("", "")); var api = new EaistoApi(storage, null); Assert.ThrowsAsync <NotAuthorizedException>(async() => await api.Search(regNumber: "111")); }
public CardsController(AppDbContext context, UserManager <User> userManager, Pager pager, EaistoApi api, IConfiguration conf, ILogger <CardsController> logger, SignInManager <User> signInManager, Settings settings, EaistoSessionManager eaistoSessionManager) { _context = context; _userManager = userManager; _pager = pager; _api = api; _conf = conf; _logger = logger; _signInManager = signInManager; _settings = settings; _eaistoSessionManager = eaistoSessionManager; }
private async Task <EaistoApi> SignIn() { var api = new EaistoApi(new MemoryStorage(), null); var captcha = await api.InitRemoteSession(); var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".jpg"); using (var file = new FileStream(path, FileMode.Create)) { captcha.CopyTo(file); captcha.Dispose(); } //Process.Start(path); Process.Start(new ProcessStartInfo("cmd", $"/c start {path}") { CreateNoWindow = true }); var code = Console.ReadLine(); File.Delete(path); await api.SignIn("login", "pass", code); return(api); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <User, IdentityRole>(options => { //options.Cookies.ApplicationCookie.AutomaticChallenge = true; options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredLength = 6; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication().AddFacebook(options => { options.AppId = Configuration["Authentication:Facebook:AppId"]; options.AppSecret = Configuration["Authentication:Facebook:AppSecret"]; }); services.AddPager(); services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddMvc(options => { options.Filters.Add <ExceptionFilter>(); options.ModelBinderProviders.Insert(0, new DateModelBinderProvider()); }) .AddDataAnnotationsLocalization( options => options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource))); services.AddSingleton <IConfiguration>(Configuration); // Add application services. services.AddTransient <IEmailSender, AuthMessageSender>(); services.AddSingleton(new CardDocxGenerator( Path.Combine(Environment.ContentRootPath, Configuration["CardTemplatePath"]), Path.Combine(Environment.ContentRootPath, Configuration["CardTemplateWithoutStampPath"]))); services.AddSingleton(new Settings(Path.Combine(Environment.ContentRootPath, "daylimit.txt"))); // Configuring session // Adds a default in-memory implementation of IDistributedCache. //services.AddDistributedMemoryCache(); //services.AddSession(options => //{ // // Set a short timeout for easy testing. // options.IdleTimeout = TimeSpan.FromMinutes(1); // options.Cookie.HttpOnly = true; //}); // Add Eaisto api //services.AddScoped<IUserStorage>(provider => // new SessionStorage(provider.GetRequiredService<IHttpContextAccessor>() // .HttpContext.Session)); services.AddScoped <EaistoSessionManager>(); services.AddScoped <IUserStorage, DbStorage>(); // Proxy var useProxy = Configuration["useproxy"] == "true"; if (useProxy) { var settings = new ProxySettings() { Host = Configuration["proxy:host"], Port = int.Parse(Configuration["proxy:port"]), Credentials = new NetworkCredential(Configuration["proxy:login"], Configuration["proxy:password"]), ConnectTimeout = 180000, ReadWriteTimeOut = 180000 }; var proxyClientHandler = new ProxyClientHandler <Socks5>(settings) { UseCookies = false, ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); }, }; var client = new HttpClient(proxyClientHandler); EaistoApi.SetHttpClient(client); } else { var handler = new HttpClientHandler { AllowAutoRedirect = false, UseCookies = false, ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); }, //SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, //CheckCertificateRevocationList = false //CookieContainer = cookies }; var client = new HttpClient(handler); EaistoApi.SetHttpClient(client); } //var proxy = new WebProxy(Configuration["proxy:address"]) //{ // //Credentials = new NetworkCredential(Configuration["proxy:login"], Configuration["proxy:password"]), // //BypassProxyOnLocal = true //}; //var httpClientHandler = new HttpClientHandler() //{ // Proxy = proxy, // AllowAutoRedirect = false, // UseCookies = false, // UseProxy = true, //}; //var client = new HttpClient(httpClientHandler); //EaistoApi.SetHttpClient(client); services.AddScoped <EaistoApi>(); }
public async Task Init() { _api = await SignIn(); }
public HomeController(EaistoApi api, Pager pager) { _api = api; _pager = pager; }