public static void ExtendTokenIssued(string username, string token) { try { using (AuthorizeEntities ctx = new AuthorizeEntities()) { TokenIssued tokenIssued = ctx.TokenIssueds.Where(t => t.Account.Uname == username && t.Val == token).SingleOrDefault(); if (tokenIssued != null) { tokenIssued.ExpireAtUtc = DateTime.UtcNow.AddSeconds(Settings.InitSetting.Instance.AuthorizationTokenLifeSpanInSecond); ctx.SaveChanges(); } } } catch (Exception ex) { Log4netLogger.Error(MethodBase.GetCurrentMethod().DeclaringType, "Error during extending TokenIssued", ex); } }
public async Task <IActionResult> RequestToken(CredentialsViewModel credentials, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var identity = await GetClaimsIdentity(credentials.UserName, credentials.Password); if (identity == null) { //return BadRequest(); return(View(credentials)); } var jwt = await Tokens.GenerateJwt(identity, _jwtFactory, identity.Name, _jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented }); TokenIssued tsi = JsonConvert.DeserializeObject <TokenIssued>(jwt); await _emailsender.SendEmailAsync("*****@*****.**", "Tokenrequested", $"<H2>Here's the token</H2><p>${tsi.auth_token}</p>"); return(View("InquireTokenApi", tsi)); }
public ITokenExpiresSetter SetIssued(DateTimeOffset issued) { Issued = new TokenIssued(issued); return(this); }