private AuthenticationTicket GetAuthenticationTicket(TUser user, RefreshToken refreshToken) { if (user == null) { throw new ArgumentNullException("user"); } if (refreshToken == null) { throw new ArgumentNullException("refreshToken"); } //get the tokn expiration from the refresh token var tokenExpiration = refreshToken.ExpiresUtc.Subtract(refreshToken.IssuedUtc); var ticket = authenticationTicketFactory.Create(user, refreshToken.ClientId, tokenExpiration); ticket.Properties.IssuedUtc = DateTime.UtcNow; ticket.Properties.ExpiresUtc = DateTime.UtcNow.AddMinutes(1); // This needs to be after Issued, not the real expiry time return(ticket); }
public async Task <AccessToken> GenerateLocalAccessToken(TUser user, string clientId, TimeSpan tokenExpiration) { if (user == null) { throw new ArgumentNullException("user"); } if (string.IsNullOrWhiteSpace(clientId)) { throw new ArgumentNullException("clientId"); } //await _signInManager.SignInAsync(user, isPersistent: true, rememberBrowser: false); var ticket = authenticationTicketFactory.Create(user, clientId, tokenExpiration); var protectedTicket = secureDataFormat.Protect(ticket); var refreshToken = await authenticationTokenFactory.CreateRefreshTokenAsync(ticket, protectedTicket); if (string.IsNullOrWhiteSpace(refreshToken)) { return(null); } var expiration = ticket.Properties.ExpiresUtc.GetValueOrDefault().DateTime; return(new AccessToken { HasRegistered = true, ExternalUserName = user.UserName, UserName = user.UserName, UserId = user.Id, Token = refreshToken, TokenType = "bearer", ExpiresIn = expiration.Second, Issued = ticket.Properties.IssuedUtc.ToString(), Expires = ticket.Properties.ExpiresUtc.ToString() }); }