public UserManagerApp Create(IdentityFactoryOptions <UserManagerApp> identitiyFactorOptions, Microsoft.Owin.IOwinContext owinContext) { DataContext db = owinContext.Get <DataContext>(); UserManagerApp user = new UserManagerApp(new UserStore <Kullanici>(db)); return(user); }
public string GetRequestCookie(Microsoft.Owin.IOwinContext context, string key) { if (context == null) { throw new ArgumentNullException("context"); } var webContext = context.Get <HttpContextBase>(typeof(HttpContextBase).FullName); var cookie = webContext.Request.Cookies[key]; return(cookie == null ? null : cookie.Value); }
public static ApplicationUserManager Create(IdentityFactoryOptions <ApplicationUserManager> options, Microsoft.Owin.IOwinContext context) { var manager = new ApplicationUserManager(new ApplicationUserStore(context.Get <ApplicationDbContext>())); manager.UserValidator = new UserValidator <ApplicationUser, int>(manager) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true }; manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireNonLetterOrDigit = false, RequireDigit = false, RequireLowercase = false, RequireUppercase = false, }; manager.UserLockoutEnabledByDefault = true; manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); manager.MaxFailedAccessAttemptsBeforeLockout = 5; manager.RegisterTwoFactorProvider("PhoneCode", new PhoneNumberTokenProvider <ApplicationUser, int> { MessageFormat = "Your security code is: {0}" }); manager.RegisterTwoFactorProvider("EmailCode", new EmailTokenProvider <ApplicationUser, int> { Subject = "SecurityCode", BodyFormat = "Your security code is {0}" }); manager.EmailService = new EmailService(); manager.SmsService = new SmsService(); var dataProtectionProvider = options.DataProtectionProvider; if (dataProtectionProvider != null) { manager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser, int>( dataProtectionProvider.Create("ASP.NET Identity")); } return(manager); }
public void AppendResponseCookie(Microsoft.Owin.IOwinContext context, string key, string value, Microsoft.Owin.CookieOptions options) { if (context == null) { throw new ArgumentNullException("context"); } if (options == null) { throw new ArgumentNullException("options"); } var webContext = context.Get <HttpContextBase>(typeof(HttpContextBase).FullName); bool domainHasValue = !string.IsNullOrEmpty(options.Domain); bool pathHasValue = !string.IsNullOrEmpty(options.Path); bool expiresHasValue = options.Expires.HasValue; var cookie = new HttpCookie(key, value); if (domainHasValue) { cookie.Domain = options.Domain; } if (pathHasValue) { cookie.Path = options.Path; } if (expiresHasValue) { cookie.Expires = options.Expires.Value; } if (options.Secure) { cookie.Secure = true; } if (options.HttpOnly) { cookie.HttpOnly = true; } webContext.Response.AppendCookie(cookie); }
private async Task InvokeInternal(IContext ctx) { #if !USE_ASPNETCORE if (ctx.Get <bool>("gotoNext")) { await Next?.Invoke(ctx); return; } #else #endif var request = await _requestMapper.MapAsync(ctx.Request, _options); bool logRequest = false; ResponseMessage response = null; MappingMatcherResult result = null; try { foreach (var mapping in _options.Mappings.Values.Where(m => m?.Scenario != null)) { // Set start if (!_options.Scenarios.ContainsKey(mapping.Scenario) && mapping.IsStartState) { _options.Scenarios.TryAdd(mapping.Scenario, new ScenarioState { Name = mapping.Scenario }); } } result = _mappingMatcher.FindBestMatch(request); var targetMapping = result?.Mapping; if (targetMapping == null) { logRequest = true; _options.Logger.Warn("HttpStatusCode set to 404 : No matching mapping found"); response = ResponseMessageBuilder.Create("No matching mapping found", 404); return; } logRequest = targetMapping.LogMapping; if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null) { bool present = request.Headers.TryGetValue(HttpKnownHeaderNames.Authorization, out WireMockList <string> authorization); if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect) { _options.Logger.Error("HttpStatusCode set to 401"); response = ResponseMessageBuilder.Create(null, 401); return; } } if (!targetMapping.IsAdminInterface && _options.RequestProcessingDelay > TimeSpan.Zero) { await Task.Delay(_options.RequestProcessingDelay.Value); } response = await targetMapping.ProvideResponseAsync(request); if (targetMapping.Scenario != null) { _options.Scenarios[targetMapping.Scenario].NextState = targetMapping.NextState; _options.Scenarios[targetMapping.Scenario].Started = true; _options.Scenarios[targetMapping.Scenario].Finished = targetMapping.NextState == null; } } catch (Exception ex) { _options.Logger.Error($"Providing a Response for Mapping '{result?.Mapping?.Guid}' failed. HttpStatusCode set to 500. Exception: {ex}"); response = ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500); } finally { var log = new LogEntry { Guid = Guid.NewGuid(), RequestMessage = request, ResponseMessage = response, MappingGuid = result?.Mapping?.Guid, MappingTitle = result?.Mapping?.Title, RequestMatchResult = result?.RequestMatchResult }; LogRequest(log, logRequest); await _responseMapper.MapAsync(response, ctx.Response); } await CompletedTask; }