public string EncryptCookie(int tenant, Guid userid, string login = null, string password = null) { var settingsTenant = TenantCookieSettingsHelper.GetForTenant(tenant); var expires = TenantCookieSettingsHelper.GetExpiresTime(tenant); var settingsUser = TenantCookieSettingsHelper.GetForUser(tenant, userid); return(EncryptCookie(tenant, userid, login, password, settingsTenant.Index, expires, settingsUser.Index)); }
public CookieStorage( IHttpContextAccessor httpContextAccessor, InstanceCrypto instanceCrypto, TenantCookieSettingsHelper tenantCookieSettingsHelper, IOptionsMonitor <ILog> options) : this(instanceCrypto, tenantCookieSettingsHelper, options) { HttpContext = httpContextAccessor.HttpContext; }
public CookieStorage( InstanceCrypto instanceCrypto, TenantCookieSettingsHelper tenantCookieSettingsHelper, IOptionsMonitor <ILog> options) { InstanceCrypto = instanceCrypto; TenantCookieSettingsHelper = tenantCookieSettingsHelper; Log = options.CurrentValue; }
public CookieStorage( IHttpContextAccessor httpContextAccessor, InstanceCrypto instanceCrypto, TenantCookieSettingsHelper tenantCookieSettingsHelper, IOptionsMonitor <ILog> options) { InstanceCrypto = instanceCrypto; TenantCookieSettingsHelper = tenantCookieSettingsHelper; HttpContext = httpContextAccessor.HttpContext; Log = options.CurrentValue; }
public CookiesManager( IHttpContextAccessor httpContextAccessor, UserManager userManager, SecurityContext securityContext, TenantCookieSettingsHelper tenantCookieSettingsHelper, TenantManager tenantManager) { HttpContextAccessor = httpContextAccessor; UserManager = userManager; SecurityContext = securityContext; TenantCookieSettingsHelper = tenantCookieSettingsHelper; TenantManager = tenantManager; }
public AuthenticationController( UserManager userManager, TenantManager tenantManager, SecurityContext securityContext, TenantCookieSettingsHelper tenantCookieSettingsHelper, CookiesManager cookiesManager, PasswordHasher passwordHasher, EmailValidationKeyModelHelper emailValidationKeyModelHelper) { UserManager = userManager; TenantManager = tenantManager; SecurityContext = securityContext; TenantCookieSettingsHelper = tenantCookieSettingsHelper; CookiesManager = cookiesManager; PasswordHasher = passwordHasher; EmailValidationKeyModelHelper = emailValidationKeyModelHelper; }
public AuthenticationController( UserManager userManager, TenantManager tenantManager, SecurityContext securityContext, TenantCookieSettingsHelper tenantCookieSettingsHelper, EmailValidationKeyProvider emailValidationKeyProvider, AuthContext authContext, AuthManager authManager, CookiesManager cookiesManager) { UserManager = userManager; TenantManager = tenantManager; SecurityContext = securityContext; TenantCookieSettingsHelper = tenantCookieSettingsHelper; EmailValidationKeyProvider = emailValidationKeyProvider; AuthContext = authContext; AuthManager = authManager; CookiesManager = cookiesManager; }
public AuthenticationTokenData AuthenticateMe([FromBody] AuthModel auth) { var tenant = TenantManager.GetCurrentTenant(); var user = GetUser(tenant.TenantId, auth.UserName, auth.Password); try { var token = SecurityContext.AuthenticateMe(user.ID); CookiesManager.SetCookies(CookiesType.AuthKey, token); var expires = TenantCookieSettingsHelper.GetExpiresTime(tenant.TenantId); return(new AuthenticationTokenData { Token = token, Expires = expires }); } catch { throw new Exception("User authentication failed"); } }
private AuthenticationTokenData AuthenticateMeWithCode(AuthModel auth) { var tenant = TenantManager.GetCurrentTenant().TenantId; var user = GetUser(auth, out _); var sms = false; try { if (StudioSmsNotificationSettingsHelper.IsVisibleSettings() && StudioSmsNotificationSettingsHelper.Enable) { sms = true; SmsManager.ValidateSmsCode(user, auth.Code); } else if (TfaAppAuthSettings.IsVisibleSettings && SettingsManager.Load <TfaAppAuthSettings>().EnableSetting) { if (TfaManager.ValidateAuthCode(user, auth.Code)) { MessageService.Send(MessageAction.UserConnectedTfaApp, MessageTarget.Create(user.ID)); } } else { throw new System.Security.SecurityException("Auth code is not available"); } var token = SecurityContext.AuthenticateMe(user.ID); MessageService.Send(sms ? MessageAction.LoginSuccessViaApiSms : MessageAction.LoginSuccessViaApiTfa); ; var expires = TenantCookieSettingsHelper.GetExpiresTime(tenant); var result = new AuthenticationTokenData { Token = token, Expires = new ApiDateTime(TenantManager, TimeZoneConverter, expires) }; if (sms) { result.Sms = true; result.PhoneNoise = SmsSender.BuildPhoneNoise(user.MobilePhone); } else { result.Tfa = true; } return(result); } catch { MessageService.Send(user.DisplayUserName(false, DisplayUserSettingsHelper), sms ? MessageAction.LoginFailViaApiSms : MessageAction.LoginFailViaApiTfa, MessageTarget.Create(user.ID)); throw new AuthenticationException("User authentication failed"); } finally { SecurityContext.Logout(); } }
private AuthenticationTokenData AuthenticateMe(AuthModel auth) { bool viaEmail; var user = GetUser(auth, out viaEmail); if (StudioSmsNotificationSettingsHelper.IsVisibleSettings() && StudioSmsNotificationSettingsHelper.Enable) { if (string.IsNullOrEmpty(user.MobilePhone) || user.MobilePhoneActivationStatus == MobilePhoneActivationStatus.NotActivated) { return new AuthenticationTokenData { Sms = true, ConfirmUrl = CommonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.PhoneActivation) } } ; SmsManager.PutAuthCode(user, false); return(new AuthenticationTokenData { Sms = true, PhoneNoise = SmsSender.BuildPhoneNoise(user.MobilePhone), Expires = new ApiDateTime(TenantManager, TimeZoneConverter, DateTime.UtcNow.Add(SmsKeyStorage.StoreInterval)), ConfirmUrl = CommonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.PhoneAuth) }); } if (TfaAppAuthSettings.IsVisibleSettings && SettingsManager.Load <TfaAppAuthSettings>().EnableSetting) { if (!TfaAppUserSettings.EnableForUser(SettingsManager, user.ID)) { return new AuthenticationTokenData { Tfa = true, TfaKey = TfaManager.GenerateSetupCode(user).ManualEntryKey, ConfirmUrl = CommonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.TfaActivation) } } ; return(new AuthenticationTokenData { Tfa = true, ConfirmUrl = CommonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.TfaAuth) }); } try { var token = SecurityContext.AuthenticateMe(user.ID); CookiesManager.SetCookies(CookiesType.AuthKey, token, auth.Session); MessageService.Send(viaEmail ? MessageAction.LoginSuccessViaApi : MessageAction.LoginSuccessViaApiSocialAccount); var tenant = TenantManager.GetCurrentTenant().TenantId; var expires = TenantCookieSettingsHelper.GetExpiresTime(tenant); return(new AuthenticationTokenData { Token = token, Expires = new ApiDateTime(TenantManager, TimeZoneConverter, expires) }); } catch { MessageService.Send(user.DisplayUserName(false, DisplayUserSettingsHelper), viaEmail ? MessageAction.LoginFailViaApi : MessageAction.LoginFailViaApiSocialAccount); throw new AuthenticationException("User authentication failed"); } finally { SecurityContext.Logout(); } }
public AuthenticationController( UserManager userManager, TenantManager tenantManager, SecurityContext securityContext, TenantCookieSettingsHelper tenantCookieSettingsHelper, CookiesManager cookiesManager, PasswordHasher passwordHasher, EmailValidationKeyModelHelper emailValidationKeyModelHelper, ICache cache, SetupInfo setupInfo, MessageService messageService, ProviderManager providerManager, IOptionsSnapshot <AccountLinker> accountLinker, CoreBaseSettings coreBaseSettings, PersonalSettingsHelper personalSettingsHelper, StudioNotifyService studioNotifyService, UserManagerWrapper userManagerWrapper, UserHelpTourHelper userHelpTourHelper, Signature signature, InstanceCrypto instanceCrypto, DisplayUserSettingsHelper displayUserSettingsHelper, MessageTarget messageTarget, StudioSmsNotificationSettingsHelper studioSmsNotificationSettingsHelper, SettingsManager settingsManager, SmsManager smsManager, TfaManager tfaManager, TimeZoneConverter timeZoneConverter, SmsKeyStorage smsKeyStorage, CommonLinkUtility commonLinkUtility, ApiContext apiContext, AuthContext authContext) { UserManager = userManager; TenantManager = tenantManager; SecurityContext = securityContext; TenantCookieSettingsHelper = tenantCookieSettingsHelper; CookiesManager = cookiesManager; PasswordHasher = passwordHasher; EmailValidationKeyModelHelper = emailValidationKeyModelHelper; Cache = cache; SetupInfo = setupInfo; MessageService = messageService; ProviderManager = providerManager; AccountLinker = accountLinker; CoreBaseSettings = coreBaseSettings; PersonalSettingsHelper = personalSettingsHelper; StudioNotifyService = studioNotifyService; UserHelpTourHelper = userHelpTourHelper; Signature = signature; InstanceCrypto = instanceCrypto; DisplayUserSettingsHelper = displayUserSettingsHelper; MessageTarget = messageTarget; StudioSmsNotificationSettingsHelper = studioSmsNotificationSettingsHelper; SettingsManager = settingsManager; SmsManager = smsManager; TfaManager = tfaManager; TimeZoneConverter = timeZoneConverter; SmsKeyStorage = smsKeyStorage; CommonLinkUtility = commonLinkUtility; ApiContext = apiContext; AuthContext = authContext; UserManagerWrapper = userManagerWrapper; }