Пример #1
0
        public static void SetAuthorizationCookie(this HttpContextBase httpContext, string username)
        {
            string          key      = Settings.InitSetting.Instance.AuthCookieName;
            DateTime        utcNow   = DateTime.UtcNow;
            PayloadIdentity identity = new PayloadIdentity()
            {
                IssuedAt = DateGenerator.ToUnixTimeStamp(utcNow),
                ExpireAt = DateGenerator.ToUnixTimeStamp(utcNow) + Settings.InitSetting.Instance.AuthorizationTokenLifeSpanInSecond,
                Username = username
            };
            JwtUtility <JwtHeader, PayloadIdentity> jwtUtil = new JwtUtility <JwtHeader, PayloadIdentity>(new JwtHeader(), identity);
            string     token  = jwtUtil.ToString();
            HttpCookie cookie = new HttpCookie(key);

            cookie.HttpOnly = false;
            cookie.Value    = token;
            cookie.Expires  = DateTime.Now.AddSeconds(Settings.InitSetting.Instance.AuthorizationTokenLifeSpanInSecond);
            httpContext.Response.Cookies.Add(cookie);
            AddTokenIssued(username, token, DateGenerator.ZeroUnixTimestamp.AddSeconds(identity.IssuedAt), DateGenerator.ZeroUnixTimestamp.AddSeconds(identity.ExpireAt));
        }
Пример #2
0
 /// <summary>
 /// Check whether the token expires yet. Timezone: UTC
 /// </summary>
 /// <returns></returns>
 public bool isTokenExpired()
 {
     return(ExpireAt <= DateGenerator.ToUnixTimeStamp(DateTime.UtcNow));
 }