public async Task CreateAsync(AuthenticationTokenCreateContext context) { var clientId = context.Ticket.Properties.Dictionary[OwinEnvironment.ClientPropertyName]; if (string.IsNullOrWhiteSpace(clientId)) { return; } var refreshTokenId = Guid.NewGuid().ToString("N"); var lifeTime = context.OwinContext.Get <string>(OwinEnvironment.ClientRefreshTokenLifeTimePropertyName); var userId = context.OwinContext.Get <string>(OwinEnvironment.UserPropertyName); var user = _applicationUserManager.FindApplciationUser(Guid.Parse(userId)); if (user == null) { return; } var token = new RefreshToken { Id = refreshTokenId.GetHash(), ClientId = Guid.Parse(clientId), Subject = context.Ticket.Identity.Name, IssuedUtc = DateTime.UtcNow, ExpiresUtc = DateTime.UtcNow.AddSeconds(Convert.ToDouble(lifeTime)), User = user }; context.Ticket.Properties.IssuedUtc = token.IssuedUtc; context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc; token.ProtectedTicket = context.SerializeTicket(); var result = await _refreshTokenManager.AddRefreshToken(token); if (result) { context.SetToken(refreshTokenId); } }