public SimpleJwt ExtractJwtFromBearerLine(string bearerTokenLine) { SimpleJwt jwt = default(SimpleJwt); try { if (bearerTokenLine.StartsWith("Bearer ")) { bearerTokenLine = bearerTokenLine.Substring(7).Trim(); } if (!string.IsNullOrEmpty(bearerTokenLine)) { var kernel = DollarTracker.Web.App_Start.NinjectWebCommon.Kernel; var appSettingMgr = kernel.Get <DollarTracker.Core.Managers.IAppSettingManager>(); var jwtSecret = appSettingMgr.GetByName("JwtSecret"); var decodedJwt = JWT.JsonWebToken.Decode(bearerTokenLine, jwtSecret); //currently hard coding. if (decodedJwt != null) { jwt = JsonConvert.DeserializeObject <SimpleJwt>(decodedJwt); } } } catch (Exception e) { } return(jwt); }
public bool IsValid(SimpleJwt simpleJwt) { bool isValidJwt = false; try { System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); dtDateTime = dtDateTime.AddSeconds(int.Parse(simpleJwt.Exp)).ToUniversalTime(); if (dtDateTime >= DateTime.UtcNow) { isValidJwt = true; } } catch (Exception e) { isValidJwt = false; } return(isValidJwt); }