Permalink
Browse files

define a new config key to determine if a if the auth cookie should l…

…ive for the whole expire period or just the validation cycle

tweak the auth cookie lifespan
  • Loading branch information...
ninianne98 committed Nov 18, 2018
1 parent fc36bac commit 94ac076215acdde97ff1bd439c6b1aca6b226238
@@ -36,6 +36,7 @@
<xs:attribute name="DataProtectionProviderAppName" type="xs:string" use="optional" />
<xs:attribute name="LoginPath" type="xs:string" use="optional" />
<xs:attribute name="ExpireTimeSpan" type="xs:int" use="optional" />
<xs:attribute name="SetCookieExpireTimeSpan" type="xs:boolean" use="optional" />
<xs:attribute name="ValidateInterval" type="xs:int" use="optional" />
</xs:complexType>
</xs:element>
@@ -159,7 +159,13 @@ public class AdditionalSettingsElement : ConfigurationElement {
set { this["ExpireTimeSpan"] = value; }
}
[ConfigurationProperty("ValidateInterval", DefaultValue = 15, IsRequired = false)]
[ConfigurationProperty("SetCookieExpireTimeSpan", DefaultValue = true, IsRequired = false)]
public Boolean SetCookieExpireTimeSpan {
get { return (Boolean)this["SetCookieExpireTimeSpan"]; }
set { this["SetCookieExpireTimeSpan"] = value; }
}
[ConfigurationProperty("ValidateInterval", DefaultValue = 30, IsRequired = false)]
public int ValidateInterval {
get { return (int)this["ValidateInterval"]; }
set { this["ValidateInterval"] = value; }
@@ -30,8 +30,25 @@ public class Startup {
CarrotSecurityConfig config = CarrotSecurityConfig.GetConfig();
bool setCookieExpireTimeSpan = config.AdditionalSettings.SetCookieExpireTimeSpan;
string loginPath = config.AdditionalSettings.LoginPath;
int expireTimeSpan = config.AdditionalSettings.ExpireTimeSpan;
double expireTimeSpan = config.AdditionalSettings.ExpireTimeSpan;
double validateInterval = config.AdditionalSettings.ValidateInterval;
if (expireTimeSpan < 5) {
expireTimeSpan = 5;
}
if (validateInterval < 5) {
validateInterval = 5;
}
//because otherwise you'll get constantly logged out
if (expireTimeSpan < validateInterval) {
expireTimeSpan = validateInterval + 1;
}
double cookieLife = (setCookieExpireTimeSpan ? expireTimeSpan : validateInterval) + 2;
app.UseCookieAuthentication(new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
@@ -40,11 +57,17 @@ public class Startup {
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
validateInterval: TimeSpan.FromMinutes(validateInterval),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)),
OnResponseSignIn = (context) => {
context.Properties.IsPersistent = true;
context.Properties.AllowRefresh = true;
context.Properties.ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(cookieLife);
}
},
SlidingExpiration = true,
ExpireTimeSpan = TimeSpan.FromMinutes(expireTimeSpan)
CookieHttpOnly = true,
ExpireTimeSpan = TimeSpan.FromMinutes(expireTimeSpan),
SlidingExpiration = true
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
@@ -27,6 +27,10 @@ public static class EmailHelper {
public static bool SendMail(string fromEmail, string emailTo, string subjectLine, string bodyText, bool isHTML) {
List<string> lst = new List<string>();
if (String.IsNullOrEmpty(emailTo)) {
emailTo = String.Empty;
}
//emailTo = emailTo.Replace(",", ";");
if (emailTo.Contains(";")) {
lst = emailTo.Split(';').Where(x => x.Length > 2).Select(x => x.Trim()).ToList();

0 comments on commit 94ac076

Please sign in to comment.